How to change Android minSdkVersion in flutter project

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.


Flutter 2.8 or Later

build.gradle update

Before Updating to Flutter 2.8

android {
    compileSdkVersion 30

defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
}

After updating to Flutter 2.8:

android {
    compileSdkVersion flutter.compileSdkVersion

defaultConfig {
        applicationId "com.example.app"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

You should change from local.properties following instruction:

  1. First go to the android->local.properties

enter image description here

  1. And changes from here

enter image description here

  1. Change like this from build.gradle
android {
    compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()

defaultConfig {
    minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
    targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

If you didn't know, Google Playstore only allows minSdkVersion to be 20 or above. But flutter has still set default minSdkVersion to 16. Can you see that you'll be always obliged to manually change for each new project?

All your suggestions above are good, but they are not the best, because you will be forced to temper with the build.gradle for each new project you create.

The best way is to modify the value of the global minSdkVersion variable from its source, so all projects, new or old, will adopt it. Remember flutter.minSdkVersion means that the variable is in flutter directory (with the sdk).

The file in question is flutter.gradle.

the address is flutter-directory/packages/flutter_tools/gradle/flutter.gradle

class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 31

    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 16

    /** Sets the targetSdkVersion used by default in Flutter app projects. */
    static int targetSdkVersion = 31

change the value of the minSdkVersion from 16 to 20 or above, and do not disturb the code in build.gradle.

If you want, you can watch a video I made on Youtube, explaining it under: flutter configure minSdkVersion from 16 to 20 or above