Flutter打包APK遇Kotlin Gradle插件版本不兼容问题求助
解决Flutter构建APK时Kotlin Gradle插件版本冲突问题
你的问题出在location插件内部硬编码了旧版Kotlin Gradle插件(1.4.20),它不会自动继承根项目定义的1.7.20版本,所以直接修改根项目的ext.kotlin_version无法覆盖这个硬编码配置。
解决方案
修改android/build.gradle文件,在subprojects块中添加依赖版本强制策略,让所有子模块统一使用你指定的Kotlin版本:
buildscript { ext.kotlin_version = '1.7.20' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.4.0' //noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.15' } } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" project.evaluationDependsOn(':app') // 新增:强制所有子模块使用根项目定义的Kotlin版本 configurations.all { resolutionStrategy.force "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.ext.kotlin_version}" resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlin_version}" resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.ext.kotlin_version}" resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.ext.kotlin_version}" } } task clean(type: Delete) { delete rootProject.buildDir }
后续操作
- 执行
flutter clean清理项目缓存 - 执行
flutter pub get重新同步依赖 - 再次尝试构建APK(
flutter build apk)
内容的提问来源于stack exchange,提问作者hudaifa77
相关产品推荐
相关产品推荐

