You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目Kotlin版本不兼容求助:元数据1.8.0与预期1.6.0不符

解决Flutter中Kotlin版本不兼容报错的分步方案

报错信息:

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.

针对你的环境(Android Studio Chipmunk 2021.2.1 Patch 2、Kotlin 1.6.10、Flutter 3.7.3),以下是详细解决步骤:

1. 统一项目Kotlin版本配置

  • 打开项目根目录下的android/build.gradle文件
  • 在buildscript块中指定Kotlin版本为1.6.10(与Android Studio内置版本一致),若不存在ext.kotlin_version则添加:
buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.2.2" // 匹配Chipmunk版本的Gradle插件
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
  • 确保allprojects块的仓库配置包含google和mavenCentral:
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

2. 匹配Gradle版本与Android Studio

  • 打开android/gradle/wrapper/gradle-wrapper.properties文件
  • 修改distributionUrl为Chipmunk对应的Gradle 7.4版本:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

3. 强制统一第三方依赖的Kotlin版本

部分第三方Flutter插件可能内置了高版本Kotlin库,需强制统一:

  • 打开android/app/build.gradle文件
  • 在文件末尾添加版本强制策略:
configurations.all {
    resolutionStrategy {
        force 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10'
        force 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10'
        force 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10'
        force 'org.jetbrains.kotlin:kotlin-reflect:1.6.10'
    }
}
  • 可选:执行以下命令查看依赖树,确认是否存在1.8.0版本的Kotlin库:
./gradlew androidDependencies

4. 彻底清理并重新构建

执行以下命令完成清理与重建:

flutter clean
rm -rf android/.gradle
rm -rf ~/.gradle/caches
cd android && ./gradlew clean build --refresh-dependencies
cd .. && flutter pub get
flutter run

5. 验证Android Studio Kotlin插件配置

  • 打开Android Studio,进入Preferences > Languages & Frameworks > Kotlin Updates
  • 确认插件版本为212-1.6.10-release-923-AS5457.46,禁止更新到更高版本
  • 重启Android Studio

内容的提问来源于stack exchange,提问作者Kaustubh Gokhale

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 10:23:24