'flutter compileSdkVersion and targetSdkVersion on Android
I would like to know that if I want my app to support new Android phone which api level is 9.0(Pie), what value should I set for compileSdkVersion and targetSdkVersion on build.gradle.
Does anyone know about this?
Solution 1:[1]
Android 9 has API level 28. Full list here.
Solution 2:[2]
Flutter needs minSdkVersion 16 and you can set the targetSdkVersion along with compliedSdkVersion to the latest API level which is 30 currently.
You can edit these properties in file /android/app/build.gradle.
minSdkVersion 16
compiledSdkVersion 30
targetSdkVersion 30
By August 2021, new apps must target at least Android 11 (API level 30). By November 2021, all apps that are being updated must target at least Android 11 (API level 30). Until then, new apps and app updates must target at least Android 10 (API level 29).
Solution 3:[3]
compileSdkVersion : version actually used to build the app
It's usually recommended to use the Flutter constant for the compileSdkVersion to always compile with the latest version of the SDK supported by Flutter : compileSdkVersion flutter.compileSdkVersion.
targetSdkVersion : compatibility mode at runtime
You can also use the constants for the targetSdkVersion but you can define a lower number if you have not tested your app on the latest Android OS.
minimumSdkVersion : minimum level of devices that will run your app
The minimumSdkVersion value should never be lower than flutter.minimumSdkVersion but can be higher if you want to be more restrictive (or if you use a dependency that requires you to raise the bar).
To be able to use your app on Android Pie (API 28), your minimumSdkVersion should be greater or equal to 28.
Simplified example of /android/app/build.gradle :
android {
compileSdkVersion flutter.compileSdkVersion
defaultConfig {
applicationId "your.bundle.id"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
}
Minimum and maximum values for Flutter
The Flutter constants are declared in this file : https://github.com/flutter/flutter/blob/7557281fb24a3ac9cd656d60b7d286e23a3ac3d3/packages/flutter_tools/gradle/flutter.gradle
Extract :
static int compileSdkVersion = 31
static int minSdkVersion = 16
static int targetSdkVersion = 31
Of course they can change with every revision of Flutter
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vinicius Pinto |
| Solution 2 | Ulysses Alves |
| Solution 3 | mbritto |
