Flutter构建Release APK报错:使用compileSdk 35需AGP 8.1.0或更高
错误信息
[!] Using compileSdk 35 requires Android Gradle Plugin (AGP) 8.1.0 or higher.
│ │ Please upgrade to a newer AGP version. The version of AGP that your project uses is likely defined in:
│ │ /Users/tusharkhatri/Downloads/bmuptodown/android/settings.gradle,
│ │ in the 'plugins' closure.
│ │ Alternatively, if your project was created with an older version of the templates, it is likely
│ │ in the buildscript.dependencies closure of the top-level build.gradle:
│ │ /Users/tusharkhatri/Downloads/bmuptodown/android/build.gradle.
│ │
│ │ Finally, if you have a strong reason to avoid upgrading AGP, you can temporarily lower the compileSdk version in the following file:
│ │ /Users/tusharkhatri/Downloads/bmuptodown/android/app/build.gradle
解决办法
方法1:升级AGP到8.1.0及以上版本
- 新模板项目:打开
android/settings.gradle,在plugins闭包中修改AGP版本:plugins { id "com.android.application" version "8.1.0" apply false id "com.android.library" version "8.1.0" apply false id "org.jetbrains.kotlin.android" version "1.8.10" apply false // Kotlin版本需匹配AGP,可按需调整 } - 旧模板项目:打开顶级
android/build.gradle,在buildscript的dependencies中修改AGP版本:buildscript { dependencies { classpath "com.android.tools.build:gradle:8.1.0" } }
方法2:临时降低compileSdk版本(不推荐长期使用)
打开android/app/build.gradle,将compileSdkVersion改为34(或其他低于35的兼容版本):
android { compileSdkVersion 34 defaultConfig { // 其他原有配置保持不变 } }
内容的提问来源于stack exchange,提问作者Tushar Khatri

