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

添加firebase_core后Flutter项目编译失败:Kotlin依赖冲突

解决Flutter添加firebase_core后的Kotlin依赖冲突问题

问题根源

编译错误是由于Kotlin标准库版本冲突导致的:项目中同时存在两个不同版本的Kotlin库(1.7.10和1.8.22),其中kotlin-stdlib-jdk8:1.7.10是你在settings.gradle中声明的Kotlin插件版本对应的依赖,而kotlin-stdlib:1.8.22是Firebase相关依赖自动引入的更高版本,两者的类文件重复导致编译失败。

修复步骤

1. 统一Kotlin插件版本

修改android/settings.gradle中的Kotlin插件版本,使其与Firebase依赖引入的版本一致:

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    // START: FlutterFire Configuration
    id "com.google.gms.google-services" version "4.3.15" apply false
    // END: FlutterFire Configuration
    // 将Kotlin版本更新为1.8.22(与报错中的stdlib版本匹配)
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

2. (可选)强制统一Kotlin依赖版本

为避免后续其他依赖引入不同版本的Kotlin库,可在android/app/build.gradle中添加强制版本配置:

android {
    // 原有配置...
}

// 添加以下代码块强制统一Kotlin版本
configurations.all {
    resolutionStrategy {
        force "org.jetbrains.kotlin:kotlin-stdlib:1.8.22"
        force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22"
    }
}

dependencies {
    // 原有依赖...
}

3. 清理并重建项目

执行以下命令清理缓存并重新构建:

flutter clean
flutter pub get
cd android && ./gradlew clean
cd .. && flutter run

验证

完成上述步骤后重新运行项目,即可解决重复类的编译错误。若仍有问题,可通过flutter pub deps命令查看依赖树,定位是否有其他第三方插件引入了旧版本Kotlin依赖。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 03:57:01