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

Firebase库版本需统一14.0.0上下,react-native-maps集成报错求助

解决React Native中react-native-maps与react-native-firebase的版本冲突问题

首先,你的核心问题是Google Play Services和Firebase库的版本不统一——你当前的配置里既有15.x版本的Firebase/Play Services依赖,又有10.0.1版本的Maps相关依赖,这必然会导致依赖冲突。下面给你一步步的解决方案:

一、统一所有Google相关库的版本

所有com.google.android.gms和com.google.firebase开头的依赖,版本号必须保持完全一致(建议统一用15.x系列,因为react-native-firebase 5.x+需要这个版本区间的支持)。

修改你的app/build.gradle依赖配置如下:

dependencies {
    implementation project(':react-native-vector-icons')

    // react-native-google-signin
    implementation(project(':react-native-google-signin')) {
        exclude group: "com.google.android.gms"
    }
    implementation 'com.google.android.gms:play-services-auth:15.0.0'

    // react-native-fbsdk
    implementation project(':react-native-fbsdk')

    // react-native-firebase
    implementation(project(':react-native-firebase')) {
        transitive = false
    }
    // RNFirebase核心依赖
    implementation "com.google.firebase:firebase-core:15.0.2"
    implementation "com.google.android.gms:play-services-base:15.0.0"
    // RNFirebase可选依赖
    implementation "com.google.firebase:firebase-auth:15.1.0"
    implementation "com.google.firebase:firebase-database:15.0.0"
    implementation "com.google.firebase:firebase-firestore:16.0.0"

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.0.2"
    implementation "com.facebook.react:react-native:+" // From node_modules

    // react-native-maps依赖 - 统一版本到15.x
    implementation(project(':react-native-maps')){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    // 这里改为和上面一致的15.0.0版本
    implementation 'com.google.android.gms:play-services-base:15.0.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.0'
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

二、额外配置:强制所有依赖使用统一版本

如果还是存在隐藏的依赖冲突(比如第三方库偷偷引入了旧版本的Google服务库),可以在项目根目录的build.gradle中添加版本强制配置,确保所有相关库都使用你指定的版本:

allprojects {
    repositories {
        // ... 保留你原有的仓库配置
    }

    // 添加这段版本强制代码
    configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-base:15.0.0'
            force 'com.google.android.gms:play-services-maps:15.0.0'
            force 'com.google.android.gms:play-services-auth:15.0.0'
            force 'com.google.firebase:firebase-core:15.0.2'
            force 'com.google.firebase:firebase-auth:15.1.0'
            force 'com.google.firebase:firebase-database:15.0.0'
            force 'com.google.firebase:firebase-firestore:16.0.0'
        }
    }
}

三、清理缓存并重新构建

完成配置修改后,一定要执行以下步骤清理缓存,避免旧依赖残留:

  • 进入android目录,运行./gradlew clean(Windows用户执行gradlew clean)
  • 删除项目根目录的node_modules文件夹,重新执行npm install或yarn install
  • 重启React Native开发服务器,重新运行项目

为什么之前的尝试没解决?

你之前把maps依赖改成15.0.1,但Firebase对应的play-services-base用的是15.0.0,版本存在细微差异;而且没有配置根目录的版本强制规则,可能还有第三方依赖偷偷引入了旧版本的库,导致冲突依然存在。

按照上面的步骤统一所有版本后,依赖冲突应该就能彻底解决了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:03:57