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

Flutter嵌入原生应用时出现Could not find com.google.firebase:firebase-core:.错误

Flutter Add-to-App集成时Firebase依赖冲突解决方案

问题背景

  • 尝试将带有firebase_core: ^2.4.1依赖的Flutter模块,通过Add-to-App功能集成到原生Android应用,但官方文档已过时
  • 原生Android项目的App级build.gradle配置如下:
implementation(platform("com.google.firebase:firebase-bom:31.0.3"))
implementation("com.google.firebase:firebase-core")
  • 最初使用Firebase BOM 31.2.0版本出现错误,切换为Flutter包对应的31.0.3版本后,执行flutter build aar同步Gradle仍报错,直接运行应用也会报错

解决步骤

  1. 强制依赖版本统一
    确保原生项目中所有Firebase依赖都通过BOM管理,不单独指定版本。确认App级build.gradle中的BOM配置唯一,且与Flutter模块依赖的版本(31.0.3)完全一致,避免混合使用不同版本的Firebase库。
  2. 清理缓存并重建
    • 执行命令清理Gradle缓存:
      ./gradlew cleanBuildCache
      ./gradlew clean
      
    • 删除Flutter模块下的.dart_tool和build目录,重新执行flutter pub get
    • 再次运行flutter build aar,然后同步原生项目的Gradle文件
  3. 排查并解决依赖冲突
    运行./gradlew app:dependencies生成依赖树,搜索Firebase相关依赖项,找到版本不一致的模块,通过exclude语句手动排除冲突:
    implementation("com.google.firebase:firebase-core") {
        exclude group: 'com.google.firebase', module: '冲突模块名'
    }
    
  4. 升级适配版本
    考虑将Flutter SDK升级到最新稳定版,同时把firebase_core升级到兼容的最新版本,避免因版本过旧导致的适配问题。

内容的提问来源于stack exchange,提问作者Vishak A Kamath

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 11:05:19