Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 445
Daibaku Avatar asked Dec 17 '22 19:12

Daibaku


1 Answers

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

like image 65
mbritto Avatar answered Dec 21 '22 10:12

mbritto