如何解决添加Firebase库失败的错误相关性

时间:2019-08-13 12:15:01

标签: android firebase gradle

我尝试通过firebase设置的说明将Firebase库添加到项目中,但是出现错误。

ERROR: In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[17.0.
0]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

Dependency failing: com.google.android.gms:play-services-measurement-api:17.0.0 -> com.google.android.gms:play-services-
measurement-impl@[17.0.0], but play-services-measurement-impl version was 17.0.1.

The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
ifact with the issue.
-- Project 'app' depends onto com.google.firebase:firebase-core@17.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-sdk@17.0.1
-- Project 'app' depends onto com.google.firebase:firebase-analytics@{strictly 17.0.0}
-- Project 'app' depends onto com.google.android.gms:play-services-ads@{strictly 18.1.1}
-- Project 'app' depends onto com.google.android.gms:play-services-ads@18.1.1
-- Project 'app' depends onto com.google.android.gms:play-services-ads-lite@{strictly 18.1.1}
-- Project 'app' depends onto com.google.firebase:firebase-core@{strictly 17.0.1}
-- Project 'app' depends onto com.google.android.gms:play-services-measurement@17.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-impl@{strictly 17.0.1}
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-api@{strictly 17.0.0}
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-sdk@{strictly 17.0.1}
-- Project 'app' depends onto com.google.android.gms:play-services-measurement@{strictly 17.0.1}

For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b
uild.gradle file.

项目build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

应用build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.project"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 17
        versionName "1.0.3"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'com.google.android.material:material:1.1.0-alpha09'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-beta01'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0-rc01'
    implementation 'androidx.preference:preference:1.1.0-rc01'
    implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.android.billingclient:billing:2.0.3'
    implementation 'com.google.android.gms:play-services-ads:18.1.1'
    implementation 'com.google.android.gms:play-services-measurement:17.0.1'
    implementation 'com.google.android.gms:play-services-measurement-sdk:17.0.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    testImplementation 'junit:junit:4.12'

    implementation 'com.google.firebase:firebase-core:17.0.1'
}

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

如何解决此问题?我试图找到相同的问题,但没有任何解决方案。

3 个答案:

答案 0 :(得分:0)

签到您的Android SDK管理器。

是否已安装?

如果不是,则安装它。

并添加此行:

implementation'com.google.firebase:firebase-auth:18.1.0'

ScreenShot

希望它会对您有所帮助。

答案 1 :(得分:0)

更改您的类路径版本:

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0' // Lower the version as they provided in SDK Configuration.
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

更改Firebase Core的版本:

com.google.firebase:firebase-core:17.0.1

或者您可以使用旧版本17.0.0

答案 2 :(得分:0)

我通过简单地删除以下几行来解决此问题:

implementation 'com.google.android.gms:play-services-measurement:17.0.1'
implementation 'com.google.android.gms:play-services-measurement-sdk:17.0.1'