flutter

Where is flutter.compileSdkVersion?


While building flutter app, I am getting this error.

One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to C:\flutter\projects\my_app\android\app\build.gradle:
android {
  compileSdkVersion 33
  ...
}

However, in my build.gradle I have :

android {
    compileSdkVersion flutter.compileSdkVersion
...
}

But I am unable to find the location where flutter.compileSdkVersion is defined. Any idea where is this defined? I have already run flutter upgrade and flutter --version returns Flutter 3.0.5.


Solution

  • Newer versions of flutter

    In recent versions, the setting comes from the flutter installation directory here:

    <flutter-installation>/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
    

    at the top of the file there is a class named FlutterExtension, which sets a number of static variables, e.g.

    static int compileSdkVersion = 34
    

    Older versions of flutter

    To strictly answer your question, the setting comes from the flutter installation directory here:

    <flutter-installation>\packages\flutter_tools\gradle\flutter.gradle
    

    Some options to change the setting:

    If you want to have the settings gathered in one place, then you could set it in the file local.properties as:

    flutter.compileSdkVersion=33
    

    And you change in your build.gradle in the following way:

    android {
      compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
    ...
    }
    

    or (obviously) just set the version direct as:

    android {
      compileSdkVersion 33
    ...
    }