45

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.

3
  • It belongs to flutter core, I think so Commented Nov 15, 2022 at 13:03
  • You have just to change this: android { compileSdkVersion flutter.compileSdkVersion ... } to : android { compileSdkVersion 33 ... } Commented Nov 15, 2022 at 13:06
  • Yes, I could do that but I don't want to have this compileSdkVersion defined in multiple places. As of now, it is picking this value flutter.compileSdkVersion from somewhere and I would rather update that. Commented Nov 15, 2022 at 13:16

8 Answers 8

73

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
...
}
Sign up to request clarification or add additional context in comments.

3 Comments

after upgrade to the latest version currently . the file only showdef pathToThisDirectory = buildscript.sourceFile.parentFile apply from: "$pathToThisDirectory/src/main/groovy/flutter.groovy" there is no define for sdk version
@YogiArifWidodo just open that file to see what's inside src/main/groovy/flutter.groovy
In the latest versions of flutter (At the time of writing this answer, latest version of flutter is 3.32.7), flutter.compileSdkVersion, flutter.minSdkVersion, flutter.minSdkVersion, etc can be found at the following location in your system: <flutter-sdk-path-in-your-system\>/packages/flutter_tools/gradle/src/main/kotlin/FlutterExtension.kt
15

Every flutter version has a compiledSdkVersion property along with others. As of Flutter 3.3.8, it is 31.

You can access the code here https://chromium.googlesource.com/external/github.com/flutter/flutter/+/refs/heads/dev/packages/flutter_tools/gradle/flutter.gradle#33

In future it might be more than 33. In case you hardcode value as 33, flutter might stop building with errors.

So the solution should be

compileSdkVersion Math.max(flutter.compileSdkVersion, 33)

now, in future if flutter changes the property to say 35, your code won't break.

Comments

5

In the latest version, the path has been changed from flutter/packages/flutter_tools/gradle/flutter.gradle

to

/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy

The defaults are following

class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 33

    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 19

    /**
     * Sets the targetSdkVersion used by default in Flutter app projects.
     * targetSdkVersion should always be the latest available stable version.
     *
     * See https://developer.android.com/guide/topics/manifest/uses-sdk-element.
     */
    static int targetSdkVersion = 33

    /**
     * Sets the ndkVersion used by default in Flutter app projects.
     * Chosen as default version of the AGP version below as found in
     * https://developer.android.com/studio/projects/install-ndk#default-ndk-per-agp.
     */
    static String ndkVersion = "23.1.7779620"

    /**
     * Specifies the relative directory to the Flutter project directory.
     * In an app project, this is ../.. since the app's build.gradle is under android/app.
     */
    String source

    /** Allows to override the target file. Otherwise, the target is lib/main.dart. */
    String target
}

2 Comments

In 2024 this should be the accepted an best answer.
groovy folder not exist, in Flutter 3.32.5 I can found only these folder: ...\flutter\packages\flutter_tools\gradle\src\main\kotlin ...\flutter\packages\flutter_tools\gradle\src\main\scripts
5

In the latest versions of flutter (At the time of writing this answer, latest version of flutter is 3.32.7), flutter.compileSdkVersion, flutter.minSdkVersion, flutter.minSdkVersion, etc can be found at the following location in your system:

<flutter-sdk-path-in-your-system\>/packages/flutter_tools/gradle/src/main/kotlin/FlutterExtension.kt

1 Comment

in 2025, this supposed to be the correct answer
1

If you just want to KNOW what values the flutter configurations are providing (and effectively in use for your particular project), for troubleshooting purposes, you can add this to the end of your app/build.gradle:

task printSdkVersions {
    doLast {
        println "The current compileSdkVersion is: ${android.compileSdkVersion}"
        println "The current targetSdkVersion is: ${android.defaultConfig.targetSdkVersion}"
        println "The current minSdkVersion is: ${android.defaultConfig.minSdkVersion}"
    }
} 

Then, in a terminal at the android folder of your flutter project (the folder containing app and gradle folders), run:

./gradlew printSdkVersions

I would recommend against attempting to track down where these flutter config values are stored... as they reside in multiple places and changing them will affect all future flutter projects or even possibly current ones.

Instead just manually override them in you local project app/build.gradle with integers as necessary... there is nothing special about the flutter values other than they conveniently set intial values for you. You will eventually need to change/override them for one reason or another anyway.

Comments

0

flutter.compileSdkVersion is the default version that defaults to installed flutter version configs. You can replace flutter.compileSdkVersion to your own custom version.

Comments

0

yes, and there you need to change it. replace:

android {
compileSdkVersion flutter.compileSdkVersion
...
}

with this:

 android {
  compileSdkVersion 33
  ...
  }

flutter.compileSdkVersion just the default one got from the flutter sdk.

Comments

0

If you want to share flutter's compileSdkVersion with the team, you could use Android Project's gradle.properties for that purpose.

Add the following in gradle.properties:

flutterTargetSdkVersion=35
flutterCompileSdkVersion=35

and change app/build.gradle to:

android {
    namespace "com.xxx.mobile.android"
    
    compileSdkVersion 'android-' + Math.max(flutter.compileSdkVersion, Integer.parseInt(flutterCompileSdkVersion))

    compileOptions {
      ...
    }

    defaultConfig {
      ...
      
      targetSdkVersion Math.max(flutter.targetSdkVersion, Integer.parseInt(flutterTargetSdkVersion))
    }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.