无法解决: com.google.firebase:firebase-core:16.0.1

我正在尝试向我的应用添加 firebase 云存储。下面是应用程序 build.gradle。但它说:无法解决:com.google.firebase:firebase-core:16.0.1。为什么?依赖项中根本没有 firebase-core。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.louise.udacity.mydict"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.google.cloud:google-cloud-storage:1.31.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
}

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

答案 1

从文档:-

现在,您的应用 gradle 文件必须明确列为依赖项,Firebase 服务才能按预期方式工作。com.google.firebase:firebase-core

加:

 implementation 'com.google.firebase:firebase-core:16.0.1'

并在顶级 gradle 文件中使用最新版本的 Google Play 服务:

classpath 'com.google.gms:google-services:4.0.2'

https://firebase.google.com/support/release-notes/android

https://bintray.com/android/android-tools/com.google.gms.google-services

注意:

您需要在顶级 gradle 文件中添加存储库,如 firebase 文档中指定的那样,并且它应该在:google()jcenter()

 buildscript {
  repositories {
          google()
          jcenter()
      }



dependencies {
  classpath 'com.android.tools.build:gradle:3.1.3'
  classpath 'com.google.gms:google-services:4.0.2'
   }
}

allprojects {
     repositories {
              google()
             jcenter()
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
 }

https://firebase.google.com/docs/android/setup


答案 2

正如@Peter哈达德上面提到的,

为了解决这个问题,我遵循了Google firebase集成指南,并在我的app/build.gradle和project/build.gradle中进行了以下更改。

如果您有任何疑问,请点击下面提到的链接

https://firebase.google.com/docs/android/setup

app/build.gradle 中的更改

implementation 'com.google.android.gms:play-services-base:15.0.2'
implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.google.firebase:firebase-messaging:17.4.0"

Project/build.gradle 中的更改

repositories {

        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.2.0'// // google-services plugin it should be latest if you are using firebase version 16.0 +
       
    }
    allprojects {
    repositories {
         google()// add it to top instead of bottom or somewhere in middle
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://maven.google.com'
        }
       
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        
    }
}

推荐