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,500
  • 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,921
  • 2
  • 26
  • 37
Aissen
  • 1,500
  • 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
  • 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,709
  • 1
  • 28
  • 44