React Native集成Firebase时Gradle报错:找不到com.google.gms.google-services:4.3.15
解决React Native集成Firebase的Gradle构建错误
错误信息
FAILURE: Build failed with an exception.
- 出错原因:
配置根项目'ToDoList'时出现问题。无法确定null的依赖项。
无法解析配置':classpath'的所有任务依赖项。
找不到com.google.gms.google-services:4.3.15:。
被以下项目依赖:project :
问题分析
com.google.gms.google-services:4.3.15为旧版本,已无法从官方仓库拉取- 根目录
build.gradle中Android Gradle Plugin(AGP)依赖未指定版本,导致构建时无法确定有效依赖
解决方案
1. 修正根目录/android/build.gradle配置
给AGP指定与React Native兼容的版本,同时升级google-services插件到稳定可用版本:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 ndkVersion = "23.1.7779620" // 指定AGP版本(适配RN 0.71+,可根据你的RN版本调整) agpVersion = "7.3.1" // 使用稳定的google-services版本 googleServicesVersion = "4.4.0" } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle:${agpVersion}") classpath("com.facebook.react:react-native-gradle-plugin") classpath("com.google.gms.google-services:${googleServicesVersion}") } } allprojects { repositories { google() mavenCentral() maven { url("$rootDir/../node_modules/react-native/android") } maven { url("$rootDir/../node_modules/jsc-android/dist") } } }
2. 修复/android/app/build.gradle中的语法错误
找到依赖部分的错误行,修正为:
dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android") implementation ("com.google.firebase:firebase-bom:32.2.2") // 如果需要使用具体Firebase组件,取消注释下面的行 // implementation 'com.google.firebase:firebase-auth' debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") if (hermesEnabled.toBoolean()) { implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } }
3. 清理Gradle缓存并重新构建
在项目根目录执行以下命令:
cd android ./gradlew clean ./gradlew build --refresh-dependencies
内容的提问来源于stack exchange,提问作者Sultan Khan
相关产品推荐
相关产品推荐

