OroshiX
OroshiX

Reputation: 714

How to resolve all google play-services dependencies with gradle?

Situation

Today, after touching nothing of the project, my gradle yelled at me and wouldn't compile the project. It failed to resolve firebase-iid, firebase-common, play-services-analytics-impl, play-services-auth-api-phone, and play-services-auth-base. So quite a mess after the weekend.

So I checked the versions of the different APIs, and upgraded the ones that needed upgrading, found out that Google had added a mandatory dependency to firebase-core, added it, then upgraded my google-services plugin, and even added a play-services-base dependency. I also upgraded firebase-messaging to version 17.0.0, and crashlytics to version 2.9.3.

But still, the build doesn't compile, with this error message:

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

Gradle Files

Here is my Gradle file (showing dependencies part only), after my attempted fixes:

apply plugin: 'com.android.application'

...
dependencies {
    implementation project(':library')
    implementation project(':otherlibrary')
    implementation 'com.android.volley:volley:1.1.0'
    implementation('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-analytics:15.0.2'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation('com.google.android.gms:play-services-ads:15.0.1') {
        exclude group: 'com.android.support', module: 'customtabs'
    }
    implementation 'com.google.android.gms:play-services-identity:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.android.gms:play-services-drive:15.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:mediarouter-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:exifinterface:27.1.1'
    implementation 'com.android.support:support-v13:27.1.1'
    // https://mvnrepository.com/artifact/com.darwinsys/hirondelle-date4j
    implementation group: 'com.darwinsys', name: 'hirondelle-date4j', version: '1.5.1'
    // For RxAndroid and RxJava
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
// (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version)
    implementation 'io.reactivex.rxjava2:rxjava:2.1.12'

    // Crashlytics
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3'

    // CSV with outputstream writer
    implementation 'com.opencsv:opencsv:4.1'

    // Gson
    implementation 'com.google.code.gson:gson:2.8.5'

    debugImplementation 'com.android.support.test:runner:1.0.2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
    androidTestImplementation 'junit:junit:4.12'
}

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

And my project-wide gradle contain these lines:

...
repositories {
    maven {
       url 'https://maven.google.com/'
       name 'Google'
    }
    ...
}
dependencies {
    ...
    classpath 'com.google.gms:google-services:4.0.1'
}
...

Official solution doesn't work

I already tried to fix the version number of multiple libraries according to the official firebase documentation, which is more or less the same as this question.
As you can read in the official documentation link, as of May 2nd, 2018, they offered a way to fix this kind of issue, but the numbers of the versions in question are not the same, and I already tried the given fix (with some downgrades now), to no avail.

Official documentation: If your app has a dependency on com.google.firebase:firebase-core:15.0.0 as well as any of the following libraries:

com.google.android.gms:play-services-analytics
com.google.android.gms:play-services-appinvite
com.google.android.gms:play-services-tagmanager
com.google.firebase:firebase-analytics
com.google.firebase:firebase-crash
com.google.firebase:firebase-dynamic-links
com.google.firebase:firebase-messaging

You will need to update the version of the latter dependency to 15.0.2. This addresses the issue where version 3.3.0 of the Google Services Gradle plugin reports: The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.0,15.0.0], [15.0.2,15.0.2]], but resolves to 15.0.2...

So how can I resolve these conflicts of versions in order for my build to compile once again correctly?

Upvotes: 4

Views: 18160

Answers (4)

Otziii
Otziii

Reputation: 2496

I added this to my build.gradle (application version) and it worked:

googleServices { disableVersionCheck = true }

(Keep in mind that this is just to disable the version check, it does not actually fix anything)

Upvotes: 2

Randive sanjivan
Randive sanjivan

Reputation: 1

Unfortunately google play service has been stopped This widows msg are generated &never run any google service performs

Upvotes: 0

ZooMagic
ZooMagic

Reputation: 666

I tried reverting back to an old build, and it seemed to work, what i found was that the gradle-wrapper.properties was using and older version (4.5) instead of the 4.6 i had in the newer project. Changing this as well as reverting to classpath 'com.android.tools.build:gradle:3.2.0-alpha08' from alpha15 seemed to do the trick. I think you can use the alpha 15 if you like, but to be sure you can use the classpath 'com.android.tools.build:gradle:3.1.2'. Along with all these changes the firebase-core and the google-gms-services should be set to version 16.0.0.

Upvotes: 0

OroshiX
OroshiX

Reputation: 714

So after a day lost in this issue, I found out that the latest version of play-services-analytics is not the one they have published in their website. It is 16.0.0 and not 15.0.2.

Android Studio told that to a colleague as a warning, but mine was unconcerned about it. So here it is, the line that changes everything:

implementation 'com.google.android.gms:play-services-analytics:16.0.0'

Upvotes: 2

Related Questions