我正在使用 React-Native 开发一个应用,并尝试将其连接到我的 Firebase 数据库。当我尝试运行我的代码(即react-native run-android)时,我得到以下信息:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
> Could not find com.google.firebase:firebase-database: 15.0.0.
我查看了 Could not find com.google.firebase:firebase-database:9.2.0 中提出的解决方案和 react native Could not find com.google.firebase ,但到目前为止都没有为我工作......
这是我的顶级 build.gradle 文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" }
}
}
这是我的应用程序级别 build.gradle 文件的一部分:
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.google.firebase:firebase-core:15.0.2"
compile "com.google.firebase:firebase-database: 15.0.0"
compile "com.google.android.gms:play-services-base:15.0.0"
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
如何解决这个问题?谢谢。
最佳答案
您需要更新您的 gradle 和 android 构建插件,将 google()
存储库添加到您的项目 build.gradle
。
将 gradle 文件夹中的 gradle-wrapper.properties
更改为:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
更新构建插件并将 google()
存储库添加到您的 build.gradle 中,以便您的项目 build.gradle 将变成这样:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// update to version 3.1.3
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
// the following is the same as google()
//maven { url "https://maven.google.com" }
google()
maven { url "https://jitpack.io" }
}
}
关于android - 找不到 com.google.firebase :firebase-database: 15. 0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50957908/