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

Flutter应用运行时Kotlin依赖版本不兼容问题求助

解决Flutter中Kotlin依赖版本不兼容问题

1. 修正根目录build.gradle的全局Kotlin配置

全局Kotlin版本通常定义在项目根目录的build.gradle中,而非app模块内。修改该文件:

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // 确保Gradle插件版本与Kotlin兼容,示例为适配1.9.0的版本
        classpath 'com.android.tools.build:gradle:7.4.2'
    }
}

plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
    id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
}

2. 在gradle.properties中强制统一Kotlin版本

添加配置强制所有依赖使用指定版本,避免冲突:

kotlin.version=1.9.0
android.jetifier.ignorelist=kotlin-stdlib,kotlin-stdlib-common
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"

3. 清理Gradle缓存并重新构建

执行命令彻底清除旧缓存,避免依赖残留:

flutter clean
cd android
# Windows用户替换为gradlew.bat
./gradlew clean
./gradlew build --refresh-dependencies
cd ..
flutter run

4. 定位并修复冲突依赖

通过依赖树找出引入旧版Kotlin的第三方库:

cd android
./gradlew app:dependencies

搜索输出中的kotlin-stdlib或kotlin-stdlib-common,找到版本不一致的依赖后,在app模块的build.gradle中强制统一版本:

dependencies {
    implementation platform("org.jetbrains.kotlin:kotlin-bom:1.9.0")
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}

5. 临时跳过元数据检查(不推荐长期使用)

若需紧急运行项目,可在app模块的build.gradle中添加编译参数跳过检查,但这仅为临时方案:

android {
    kotlinOptions {
        freeCompilerArgs += ["-Xskip-metadata-version-check"]
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 01:12:43