2

I need to change SDK version on Android but now on build.gradle (in root/android/app/build.gradle) looks like

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.bla.bla"
        minSdkVersion flutter.minSdkVersion  // here is the cause
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

I know I can replace with flutter.minSdkVersion to version code manually (I tried, It works). But I need to know the best way...

Update: I'm Using Flutter 2.8.1 • channel stable & Dart 2.15.1

Anushka Pubudu
  • 389
  • 3
  • 10

4 Answers4

2

You can use Math.max:

defaultConfig {
        applicationId "com.bla.bla"
        minSdkVersion Math.max(flutter.minSdkVersion, 19)  // here is the change
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

But personally I would just use the specific version number.

Michele Volpato
  • 700
  • 6
  • 14
0

With the new Flutter projects (2.8.0), with the 'Flutter style', you able to change minimum sdk version in local.properties (instead of editing app/build.gradle file).

# android/local.properties

flutter.minSdkVersion=19
Look in android/app/build.gradle file, you'll see the variable 

constraint like this:

# android/app/build.gradle

android {

  defaultConfig {
    minSdkVersion flutter.minSdkVersion
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
  }
}
0

You can directly change the min SDK version in build.gradle file

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.bla.bla"
    minSdkVersion 'You can set version // for ex.16'  
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}
keyur
  • 151
  • 13
0

None of the above methods is working or is reliable.

Please follow the steps below to fix this issue:

Step 1. Locate the Flutter SDK on your device. Step 2. Locate the packages folder inside.

enter image description here

Step 3. Go inside packages -> flutter-tools -> gradle -> flutter

enter image description here

Step 4. Double-click the flutter folder and open it in notepad to edit.

Step 5. Edit the required min SDK variable inside and save the file.

enter image description here

Step 6. Rerun the app and you will find no error now.

Thanks :)

Sweta Jain
  • 3,248
  • 6
  • 30
  • 50