21

I have created a new Flutter project, and this is how the minSdkVersion looks like in the app/build.gradle file:

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

Where is the value of flutter.minSdkVersion set?

Note that previously, that config value looked like the following:

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"
}

Also, this is the content of the android/local.properties file:

sdk.dir=/Users/usernaem/Library/Android/sdk
flutter.sdk=/Users/username/flutter
flutter.buildMode=release
flutter.versionName=1.0.0
flutter.versionCode=1

As you can see, the value of flutter.minSdkVersion is not set there, but the project can be compiled and built successfully.

Where are the flutter.minSdkVersion and flutter.targetSdkVersion variables initialized?

P.S. related issue: https://github.com/flutter/flutter/issues/95533

B Faley
  • 17,120
  • 43
  • 133
  • 223
  • Does this answer your question? [How to change Android minSdkVersion in flutter project](https://stackoverflow.com/questions/52060516/how-to-change-android-minsdkversion-in-flutter-project/70316521#70316521) – Jahidul Islam Dec 26 '21 at 11:11
  • Obviously not! Previously the value was something like `minSdkVersion 19` and it was easy to change it. But now it's set via a variable `minSdkVersion flutter.minSdkVersion` and I don't know where it's set. – B Faley Dec 26 '21 at 11:15
  • go to android folder and then android->local.properties and here you change your require SDK version – Jahidul Islam Dec 26 '21 at 11:17
  • I cannot see them there. Updated the question with the content of the `local.properties` file. – B Faley Dec 26 '21 at 11:20

4 Answers4

15

Go to this file in your flutter extracted folder:

flutter/packages/flutter_tools/gradle/flutter.gradle

There you can find all static variables.

Jay Goti
  • 159
  • 2
2

Just replace flutter.minSdkVersion with your required value such as 19 like old style

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.projectname"
    minSdkVersion 19
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}
0

Put in your android/local.propertie file the variable:

Example:

flutter.minSdkVersion=21

And change in android/app/build.gradle

localProperties.getProperties('flutter.minSdkVersion') // flutter.minSdkVersion 
HFranco
  • 592
  • 6
  • 9
  • It should be localProperties.getProperty('flutter.minSdkVersion').toInteger() – Levi Roelofsma Jul 18 '22 at 08:57
  • For me works without .toInteger() – HFranco Jul 18 '22 at 20:23
  • local.propertie is usually ignored in the .gitignore. So, the setup will be necessary on each machine. Is there any other way that only affects the given project and is included in git? Why changing the build.gradle is not an option? Can we create a separate file like "project.properties" instead (idk how since the reading is done using an internal method)? – Guillem Poy Dec 18 '22 at 08:51
0

Follow the path /android/app/build.gradle

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.sample.com"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
    minSdkVersion 23
    targetSdkVersion 33
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true

}
Shahoriar Nahid
  • 164
  • 6
  • 11