Flutter打包APK报错:更新Kotlin Gradle插件后问题仍存在
Flutter打包APK时Kotlin版本更新后仍报错的解决方法
问题描述
执行flutter build apk --release命令时触发错误:
[!] Your project requires a newer version of the Kotlin Gradle plugin. Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update C:\Users\jmichelena\Desktop\Buenas\hola\android\build.gradle: ext.kotlin_version = '<latest-version>'
已在android/build.gradle文件中将Kotlin版本更新为1.7.20,代码片段如下,但错误依旧:
buildscript { ext.kotlin_version = '1.7.20' repositories { google() mavenCentral() } }
解决步骤
- 检查Kotlin插件依赖同步:除了设置
ext.kotlin_version,还要确保buildscript的dependencies块里的Kotlin Gradle插件引用了该变量,版本必须一致。建议直接升级到当前最新稳定版(比如1.9.20),示例:buildscript { ext.kotlin_version = '1.9.20' repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:7.4.2" // 注意Gradle插件版本要和Kotlin版本兼容 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } - 清理缓存重新构建:
- 执行命令
flutter clean清理项目缓存 - 删除项目
android/.gradle文件夹 - 重新运行
flutter build apk --release
- 执行命令
- 核对Gradle版本兼容性:Kotlin版本与Android Gradle插件版本需匹配,避免混用不兼容的版本组合
- 确认修改文件路径:确保修改的是项目根目录下的
android/build.gradle,而非android/app/build.gradle
内容的提问来源于stack exchange,提问作者jmichelena
相关产品推荐
相关产品推荐

