简体   繁体   中英

Gradle sync fails: com.google.android.gms:play-services-basement and com.google.firebase:firebase-common

I am trying to include firebase to my android project as described in the official firebase documenation. The app is very basic and uses Google's vision APIs.

Error that I'm getting:

Gradle sync failed: Failed to notify dependency resolution listener. The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[11.0.4,11.0.4], [15.0.1,15.0.1]], but resolves to 15.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

I've already tried a few solutions from similar questions posted on the site which didn't work for me. More importantly, I'd like to understand the root cause, rather than blindly tinkering with versions.

Below are my gradle files:

Module level

apply plugin: 'com.android.application'
/* ... */    
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:2.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.gms:play-services:11.0.4'
    implementation 'com.google.firebase:firebase-core:16.0.1'
}

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

Project level

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

Running ./gradlew app:dependencies gives:

Failed to notify dependency resolution listener.

The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[11.0.4,11.0.4], [15.0.1,15.0.1]], but resolves to 15.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

The library com.google.firebase:firebase-common is being requested by various other libraries at [[11.0.4,11.0.4]], but resolves to 16.0.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

Update the following:

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

to this:

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

Also as stated in the docs:

Note: Don't use the combined play-services target. It brings in dozens of libraries, bloating your application. Instead, specify only the specific Google Play services APIs your app uses.

Therefore, remove this:

 implementation 'com.google.android.gms:play-services:11.0.4'

And add a specific google play service api with an updated version, example implementation 'com.google.android.gms:play-services-auth:16.0.1'

Also update the firebase-core to version 16.0.4

Check here for more info:

https://developers.google.com/android/guides/setup


When you get this error:

The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1.

It means that a direct dependency (inside the google maven repository) that you are using in gradle, is using the transitive dependency com.google.android.gms:play-services-basement .

Here in this case firebase-core:16.0.1 uses play-services-basement:15.0.1 and the latest version of play-services-basement is 16.0.1 , thus you get this error.

You can also check this in October 2, 2018 they did the following:

Minor internal feature updates were made to some core libraries (play-services-auth, play-services-base, play-services-basement, play-services-flags, play-services-stats, play-services-tasks) used by other Google Play services libraries.

Also they released the com.google.android.gms:play-services-basement:16.0.1 and com.google.firebase:firebase-core:16.0.4

Also check my answer here:

Android | Cannot add all Google libraries for version 15.0.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM