Flutter构建报错:Kotlin模块版本不兼容问题求助
Kotlin版本不兼容导致Flutter构建失败
报错详情
e: C:/Users/Omer/.gradle/caches/transforms-3/444158a5a1a4ac8afe9995117e41cb16/transformed/jetified-activity-1.7.2/jars/classes.jar!/META-INF/activity_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/96e72aa9eba981daa2622d9cddde23a6/transformed/lifecycle-livedata-core-2.6.1/jars/classes.jar!/META-INF/lifecycle-livedata-core_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/11f9be4c8aaa5d617a7cc1ff1672b6c0/transformed/lifecycle-livedata-2.6.1/jars/classes.jar!/META-INF/lifecycle-livedata_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/7ca6a80d16b19d6ba21adc9e99e0a094/transformed/lifecycle-viewmodel-2.6.1/jars/classes.jar!/META-INF/lifecycle-viewmodel_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/d4006b5d1fcd84b1354bccc2a4c2c3b3/transformed/jetified-lifecycle-viewmodel-savedstate-2.6.1/jars/classes.jar!/META-INF/lifecycle-viewmodel-savedstate_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/ec9c5c926719529ab2408cb95b7aa427/transformed/jetified-core-ktx-1.10.1/jars/classes.jar!/META-INF/core-ktx_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/19827b4a5aaa9813188135a9c7d867bd/transformed/core-1.10.1/jars/classes.jar!/META-INF/core_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/943f3ada3ec6ed557111efe6a04b12b5/transformed/lifecycle-runtime-2.6.1/jars/classes.jar!/META-INF/lifecycle-runtime_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/modules-2/files-2.1/androidx.lifecycle/lifecycle-common/2.6.1/10f354fdb64868baecd67128560c5a0d6312c495/lifecycle-common-2.6.1.jar!/META-INF/lifecycle-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/transforms-3/2e721f1bf4bd80f56fac75a967298751/transformed/jetified-savedstate-1.2.1/jars/classes.jar!/META-INF/savedstate_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0. e: C:/Users/Omer/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.0/cd65c21cfd1eec4d44ef09f9f52b6d9f8a720636/kotlin-stdlib-common-1.9.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
当前项目级build.gradle配置
buildscript { ext.kotlin_version = '1.9.0' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Add the dependency for the Google services Gradle plugin classpath 'com.google.gms:google-services:4.3.15' } }
已尝试的操作
- 更新所有依赖至最新版本
- 尝试社区常见解决方案(StackOverflow、GitHub)
- 执行
flutter clean后重建 - 清除Gradle缓存
- 修改Kotlin版本号
- 添加指定配置项
解决方案
1. 统一项目与模块的Kotlin版本
打开android/app/build.gradle,确保依赖中的Kotlin版本和项目级配置一致:
dependencies { // 确认该行存在且版本匹配 implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }
2. 升级Android Gradle Plugin(AGP)版本
Kotlin 1.9.0需要AGP 7.4.0及以上版本支持,修改项目级build.gradle中的AGP版本:
classpath 'com.android.tools.build:gradle:7.4.2' // 可替换为更高兼容稳定版
3. 强制统一Kotlin依赖版本
在项目级build.gradle中添加版本强制策略,避免依赖冲突:
allprojects { repositories { google() mavenCentral() } configurations.all { resolutionStrategy { force "org.jetbrains.kotlin:kotlin-stdlib:1.9.0" force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0" force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0" force "org.jetbrains.kotlin:kotlin-stdlib-common:1.9.0" } } }
4. 彻底清除缓存并重建
- 执行
flutter clean - 删除项目根目录下的
.gradle文件夹 - 删除本地Gradle缓存目录(Windows路径:
C:/Users/Omer/.gradle/caches) - 重启Android Studio,依次执行
flutter pub get和重新构建项目
5. 升级Flutter SDK版本
确保Flutter SDK版本与Kotlin 1.9.0兼容,执行命令升级到最新稳定版:
flutter upgrade
内容的提问来源于stack exchange,提问作者Omer Sha'ashua
相关产品推荐
相关产品推荐

