找不到com.google.firebase:firebase数据库:15.0.0

时间:2018-06-20 22:26:04

标签: android firebase react-native firebase-realtime-database

我正在使用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.0react 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"

如何解决此问题?谢谢。

2 个答案:

答案 0 :(得分:3)

您需要更新gradle和android build插件,并将google()存储库添加到项目build.gradle

通过将gradle文件夹中的gradle-wrapper.properties更改为:

将gradle版本更新为至少版本 4.4

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" }
    }
}

答案 1 :(得分:1)

在此块中添加google():

allprojects {
    repositories {
        google()   // add this
        // others here...
    }
}

这是所有Android,Firebase和Play服务依赖项所需的存储库。您也应该在这里添加它:

buildscript {
    repositories {
        google()
        jcenter()
    }
}

Read more about it here