2

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.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Mukul Gupta
  • 2,310
  • 3
  • 24
  • 39

1 Answers1

3

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

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • After applying the changes you suggested and using `com.google.android.gms:play-services-vision:16.2.0` instead of the `play-services` target, I now get: `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.` Also, could you explain why you suggest downgrading gradle to 3.1.0 and upgrading google-services to 4.1.0? – Mukul Gupta Nov 10 '18 at 23:15
  • oops nevermind gradle keep it the same, keep gradle the same and sync also what google service api did you use with which version? – Peter Haddad Nov 10 '18 at 23:35
  • The error's the same. I'm using mobile vision APIs. Previously, I was using the entire target: play-services-11.0.4 as mentioned in the gradle file. – Mukul Gupta Nov 10 '18 at 23:54
  • Thanks. Upgrading `firebase-core` to 16.0.4 worked. Setting classpath to `com.google.gms:google-services:4.1.0` was not required. Could you explain or point out some documentation that made you realize that the specific version should be updated? Could you also update the answer with the suggestions in comments that eventually made it to work? – Mukul Gupta Nov 11 '18 at 10:09
  • I said to update to version 4.1.0 just to prevent any other errors from occurring, but yes it may have been useless. The most important thing was using version 3.3.0+ which you are already doing. Also 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 some library is using `play-services-basement` as a transitive dependency, so after updating the versions of firebase and google-services it may fix the error. – Peter Haddad Nov 11 '18 at 11:07
  • check my comments here: https://stackoverflow.com/questions/50760171/failed-to-resolve-implementation-com-google-firebasefirebase-messaging15-0-2/ – Peter Haddad Nov 11 '18 at 11:08