无法解析“ com.google.firebase:firebase-auth:16.0.3”的依赖项

时间:2018-09-12 07:31:25

标签: android firebase android-gradle firebase-authentication android-gradle-3.0

我正在尝试将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
    }

3 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

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

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