无法解决 'com.google.firebase:firebase-auth:16.0.3' 的依赖关系

Could not resolve dependency for 'com.google.firebase:firebase-auth:16.0.3'

我正在尝试将 firebase 身份验证添加到我的项目中。同步 build.gradle:

时出现以下错误
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.firebase:firebase-auth:16.0.3.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.firebase:firebase-auth:16.0.3.
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-auth:16.0.3.
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.firebase:firebase-auth:16.0.3.
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-auth:16.0.3.

我的应用级别 gradle 文件如下:

  apply plugin: 'com.android.application'

    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "com.example.muzammil.maptestingproject"
            minSdkVersion 15
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        productFlavors {
        }
    }

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.google.android.gms:play-services-maps:15.0.1'
        implementation 'com.google.android.gms:play-services-vision:15.0.2'
        implementation 'com.google.android.gms:play-services-location:15.0.1'
        implementation 'com.google.android.gms:play-services-maps:15.0.1'


        implementation 'com.google.firebase:firebase-core:16.0.3'
        implementation 'com.google.firebase:firebase-database:16.0.1'
        implementation 'com.android.support:design:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        implementation 'com.google.firebase:firebase-auth:16.0.3'
        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'
    }
    apply plugin: 'com.google.gms.google-services'

项目级别 gradle 文件是:

 buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'
           classpath 'com.google.gms:google-services:4.0.1'
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
 maven { url 'https://jitpack.io' }
        }
    }

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

project level gradle 文件中尝试将 google-services 插件 更新到最新版本:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.1.0' // update version
    }
}

它抱怨 debugUnitTest 缺少依赖项,而您在模块级别 build.gradle 中没有指定任何 debug 构建类型。它应该看起来像这样,例如:

buildTypes {
    debug {
        applicationIdSuffix '.debug'
        // signingConfig signingConfigs.debug
        minifyEnabled false
        debuggable true
        jniDebuggable true
        zipAlignEnabled true
        renderscriptDebuggable true
        pseudoLocalesEnabled false
        shrinkResources false
    }

此外,考虑将 androidTestImplementation "com.android.support.test:rules:1.0.2" 添加为依赖项...并可能将 testBuildType "debug" 添加到 defaultConfig

由于正常方式不起作用,假设您使用的是 Android Studio,您可以通过以下方式尝试使用 GUI 方式:

  1. 清理项目
  2. 重建项目
  3. Tools、select Firebase
  4. 身份验证
  5. 电子邮件和密码验证
  6. 连接到 Firebase
  7. 添加依赖项
  8. 按照说明检查您的身份验证状态