0

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
  • 288
  • 3
  • 8
  • refer [here](https://stackoverflow.com/questions/52060516/how-to-change-android-minsdkversion-in-flutter-project) – gretal Dec 21 '21 at 06:22
  • @gretal I know I can replace with flutter.minSdkVersion to version code manually (I tried, It works). But I need to know the best way... – Anushka Dec 21 '21 at 06:24
  • 1
    I think that can be done only manually. – gretal Dec 21 '21 at 06:35
  • check out this https://stackoverflow.com/questions/52060516/how-to-change-android-minsdkversion-in-flutter-project/70316521#70316521 – Jahidul Islam Dec 24 '21 at 12:44
  • Are you asking if it's possible to redefine flutter.minSdkVersion itself? I don't think it is. – Nerdy Bunz Dec 25 '21 at 20:11

3 Answers3

1

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
  • 565
  • 3
  • 13
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
  }
}
Tasnuva Tavasum oshin
  • 2,696
  • 1
  • 13
  • 18
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
  • 198
  • 6