在我的 React Native 应用程序中,我添加了 firebase ,所以我的根 gradle 和应用程序 gradle 是:
根build.gradle:
buildscript {
ext {
...
}
repositories {
google()
maven {
url 'https://maven.fabric.io/public'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
jcenter()
}
}
...
应用程序构建.gradle:
...
dependencies {
...
implementation 'com.android.support:design:${rootProject.ext.supportLibVersion}'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.firebase:firebase-core:16.0.1'
}
// 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'
当我运行项目时,应用程序崩溃了;但是当我评论这一行时:
// apply plugin: 'com.google.gms.google-services'
应用程序正确运行。
我被毁了,请帮助我:)
对我来说,问题是“google-service.json”中的“package_name”与“project/app-module/build.gradle”中的“applicationId”不同
我遇到了同样的问题...崩溃的原因是没有将 Android 应用程序添加到我的 firebase 项目中(需要 google-services.json)。检查此错误“模块根文件夹中缺少文件 google-services.json。没有它,Google 服务插件无法运行”
对我来说,问题出在 /android/build.gradle 的版本中
// the google-services plugin past version 4.3.15 as it requires gradle >= 7.3.0 classpath 'com.google.gms:google-services:4.4.2'
仔细检查正确的版本