Search code examples
androidflutterandroid-sdk-tools

Flutter : How to change Android minSdkVersion in Flutter Project?


I was trying to start a flutter project for an App using Bluetooth to communicate. For that, I was using flutter blue.

Unfortunately, when trying to run (on an Android device) the first example I created I was met with the following error:

FAILURE: Build failed with an exception.

  * What went wrong:
  Execution failed for task ':app:processDebugManifest'.
  > Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:flutter_blue] /home/maldus/Projects/flutter/polmac/build/flutter_blue/intermediates/manifests/full/debug/AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
            or increase this project's minSdk version to at least 19,
            or use tools:overrideLibrary="com.pauldemarco.flutterblue" to force usage (may lead to runtime failures)

If I were on Android Studio, I'd know how to bump up the Android minSdkVersion, but on a Flutter project (using VSCode) I was a little lost.

Is it possible to increase the minSdkVersion with Flutter, and how?


Solution

  • It is indeed possible to increase minSdkVersion, but it took me way too much time to find it out because google searches mostly yields as result discussions about the absolute minimum Sdk version flutter should be able to support, not how to increase it in your own project.

    Like in an Android Studio project, you have to edit the build.gradle file. In a flutter project, it is found at the path ./android/app/build.gradle.

    The parameter that needs to be changed is, of course, minSdkVersion 16, bumping it up to what you need (in this case 19).

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.projectname"
        minSdkVersion 19 //*** This is the part that needs to be changed, previously was 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    

    Seems obvious now, but took me long enough to figure it out on my own.