20

I have this in my top-level build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

And in my app-level gradle:

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

dependencies {
    compile 'com.google.android.gms:play-services-ads:9.0.1'
}

And I get this error when sync-ing gradle:

Please fix the version conflict either by updating the version of the google-services plugin […] or updating the version of com.google.android.gms to 9.0.0.

Yet I'm already using 9.0.1, I don't get it.

Aissen
  • 1,440
  • 1
  • 11
  • 17

3 Answers3

59

That's because you should always put the "apply plugin" clause at the bottom for google-services, since it looks for the already-added dependencies. Do it like this in your app-level gradle:

dependencies {
    compile 'com.google.android.gms:play-services-ads:9.0.1'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

This is hidden in the Firebase documentation, but applies even if you don't use Firebase.

Note : Update Google Repository also.

Shalu T D
  • 3,525
  • 2
  • 23
  • 33
Aissen
  • 1,440
  • 1
  • 11
  • 17
  • 3
    Same problem, mine was already set like this and made no difference. What did work for me was updating firebase-core to 9.0.1, appears both must be upgraded at the same time (writing this 9.0.2 of the play services has been released, updating both it and the firebase-core worked again) – Rick Tonoli Jun 06 '16 at 19:17
  • Thanks @RickTonoli I didn't use firebase in my case. – Aissen Jun 07 '16 at 07:50
  • Great answer, saved me a lot of headache! :) – Alessandro Jun 17 '16 at 17:26
  • Thanks @RickTonoli! – Recomer Jun 20 '16 at 08:51
  • i already have the apply plugin for google-services at the bottom. Still see the error. I'm not using firebase. – Muhammad Babar Sep 06 '16 at 12:56
  • 2
    @MuhammadBabar : verify it's not there twice (it should only be at the bottom). And that you have everything upgraded at the same time as Rick said. – Aissen Sep 07 '16 at 09:56
  • 1
    The problem was caused by a library which in turn using the latest version of support library which was causing the problem. I fixed it by using following script `compile ('com.xyz.libraryName'){ exclude module: 'support-v4' }` – Muhammad Babar Sep 07 '16 at 11:15
  • this should be THE MOST HIGH VOTED ANSWER. i was digging around for solution 2 days straight and it was just this simple thing to move plugin to bottom. thanks man. – deejay Oct 02 '16 at 20:39
  • 1
    Nice tip: after moving apply plugin: 'com.google.gms.google-services' to the bottom of your file, make sure you have apply plugin: 'com.google.gms.google-services' only once in your build.gradle file... :) – Bruno Carrier Dec 19 '16 at 03:13
4

Check the version of google services that you have in your root level build.gradle. This should be 3.0.0 or higher:

buildscript {
    ext.kotlin_version = '1.0.2'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
MrBigglesworth
  • 350
  • 1
  • 8
  • That's exactly what I have in my question: "top-level build.gradle" means "root level build.gradle". – Aissen Jun 06 '16 at 07:41
  • 2
    Have you tried upgrading Google Repository and Google Play Services via the SDK Manager? And you have no other dependencies that might conflict, like firebase or other google things? – MrBigglesworth Jun 07 '16 at 13:10
  • I had upgraded to the latest available versions, and no confliciting dependencies. I solved the issue the way I posted in my answer :-) – Aissen Jun 07 '16 at 16:00
  • Updating my Google Repository and Google Play Services solved the problem here - thanks @MrBigglesworth ! Had to change "compile 'com.google.android.gms:play-services:7.0.0'" to "compile 'com.google.android.gms:play-services-ads:9.0.1'" – PayToPwn Jan 30 '17 at 12:47
1

Update com.google.firebase:firebase-messaging:9.0.2 and com.google.android.gms:play-services:9.0.2 to same version(latest version) and sync the project. Check if plugin is added on bottom like this.

dependencies {


compile 'com.android.support:appcompat-v7:24.0.0'
..................

}
apply plugin: 'com.google.gms.google-services'
Ameer
  • 2,677
  • 1
  • 26
  • 42