已更新Android build.gradle仍提示使用旧版Kotlin Gradle插件求助
解决Android Gradle插件与Kotlin版本冲突问题
核心原因
你项目中的location依赖模块硬编码了Kotlin Gradle插件版本1.4.20,低于Android Gradle插件要求的1.5.20+,且该依赖未继承你项目根配置的Kotlin版本,导致版本冲突。修改项目根目录的ext.kotlin_version无法覆盖依赖内部指定的旧版本,因此问题持续存在。
解决方案
方法1:强制所有模块使用统一Kotlin版本
在项目根目录的android/build.gradle中添加版本强制策略,确保所有依赖模块使用你指定的Kotlin版本:
buildscript { ext.kotlin_version = '1.7.20' repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:7.4.2" // 确保AGP版本与Kotlin版本兼容 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() } // 添加版本强制配置 configurations.all { resolutionStrategy { force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } }
方法2:升级location依赖到最新稳定版
检查你使用的location插件(如Flutter的location包)的最新版本,在pubspec.yaml中更新依赖:
dependencies: location: ^6.0.1 # 替换为当前最新稳定版本号
更新后执行flutter pub get同步依赖,再尝试构建。
方法3:手动修改依赖模块配置(临时方案)
若前两种方法无效,可直接修改本地缓存的location模块配置:
- 找到依赖缓存目录:
~/.pub-cache/hosted/pub.dartlang.org/location-[版本号]/android/build.gradle - 打开文件,将其中的
kotlin-gradle-plugin版本改为1.7.20 - 同步项目后重新构建
验证步骤
- 执行
flutter clean清除旧构建缓存 - 执行
flutter pub get同步依赖 - 重新构建App Bundle:
flutter build appbundle
内容的提问来源于stack exchange,提问作者fikri akhdi maulana
相关产品推荐
相关产品推荐

