179

So this morning I started updating to the latest version of my project libraries.

I'm trying to update GCM to the latest version 9.2.0, but I get this error:

Error:Execution failed for task ':app:processDebugGoogleServices'. Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.

This is how I have my code:

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'
    classpath 'com.google.gms:google-services:3.0.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}

And then:

dependencies {
    ...

    compile "com.google.android.gms:play-services-gcm:9.2.0"

    ...
}

Anyone having the same issue/fixed the same issue?

Thanks.

EDIT

Apparently you have to apply your GSM plugin at the bottom of your app/build.gradle file. Else, version 9.2.0 will cause conflict in your project.

For reference, this is how my app/build.gradle file looks like now:

apply plugin: "com.android.application"
apply plugin: "com.neenbedankt.android-apt"

android {
    ...
}

dependencies {
    ...

    // Google Cloud Messaging
    compile "com.google.android.gms:play-services-gcm:9.2.0"

    ...
}

apply plugin: "com.google.gms.google-services"
herrmartell
  • 3,057
  • 4
  • 18
  • 27
  • same issue here, I rolled back to 9.0.0 – mbonnin Jun 30 '16 at 23:08
  • @mbonnin I ended up doing the same. But would surely like to know what's going on here. Haven't been lucky finding an answer yet. – herrmartell Jul 01 '16 at 14:47
  • 2
    And then 9.0.0 has this bug http://stackoverflow.com/questions/37361651/firebase-crash-library-nullpointerexception-in-the-console and the solution seems to be to update to 9.2.0.... Which is not possible thanks to the bug here :-( – mbonnin Jul 07 '16 at 17:30
  • 6
    it's working if I apply the plugin at the end of the build.gradle file like Gusthema says bellow – mbonnin Jul 07 '16 at 17:42
  • Read how to correct this issue the right way in my post [here](http://stackoverflow.com/a/41430554/3997720). – Pedro Varela Jan 09 '17 at 15:39
  • It does not make too much sense... but it works by writing that "apply plugin" at the end of the build.gradle – Massimo Mar 02 '17 at 10:56

11 Answers11

507

Do you have the line

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

line at the bottom of your app's build.gradle file?

I saw some errors when it was on the top and as it's written here, it should be at the bottom.

Gusthema
  • 5,436
  • 1
  • 15
  • 15
  • This is not the issue. And according to the official documentation, all plugins should be applied at the top. https://developer.android.com/studio/build/index.html – herrmartell Jul 05 '16 at 20:56
  • 11
    That's not true, gms plugin should be in the bottom of the file as you can see here on the docs for gms: https://developers.google.com/android/guides/google-services-plugin – Gusthema Jul 06 '16 at 22:18
  • 1
    I stand corrected. Regardless, this will not solve the problem. – herrmartell Jul 06 '16 at 23:05
  • 1
    I'm not sure why the first time I tried it, it did not work. Just tried it again because of @mbonnin 's comment, and it's working now. Thank you. – herrmartell Jul 07 '16 at 17:56
  • 9
    I had added this line in the beginning of the file, but it worked after putting it at the bottom. – SHA2NK Oct 01 '16 at 04:30
  • I get the following after adding the line: * What went wrong: A problem occurred evaluating root project 'android'. > Plugin with id 'com.google.gms.google-services' not found. – Richard Oct 28 '16 at 15:28
  • 2
    Adding the plugin at the bottom resolved the version conflict. – user_1989 Mar 14 '17 at 06:40
  • 1
    Thank you this worked for me. I wonder why we need to put this line of code at the bottom ? – viper May 04 '17 at 08:18
  • That's bizarre. Any possible explanations? – Luke Jul 19 '17 at 20:43
  • Crazy stuff!!! As you said I just moved the 'apply plugin' 'from top to bottom and it worked... – Fernando Bonet Aug 01 '17 at 15:13
  • This line is important :: :) line at the bottom of your build.gradle file? – Jithu P.S Aug 18 '17 at 09:34
  • This is upsurd... But it worked :D :D This should be reported to Google – Jimit Patel Nov 06 '17 at 08:59
  • That's true, "apply plugin: 'com.google.gms.google-services'" plugin should be in the bottom of the file, it works for me, – Kuldeep Singh Apr 29 '18 at 07:37
54

Just put this line at the bottom of your app-module's (not project root's) gradle file.

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

Then rebuild your project.

Vikas
  • 4,263
  • 1
  • 34
  • 39
11

I had the same problem, today 2016 - october - 06 I solved with this:

I changed all dependencies that began with 9.?.? to 9.6.1 I compiled with sdk version 24 and target version 17.

There is another packages in my solution because I used more things then only authentication.

After changed your build.gradle (Module:app) with the code below do it:

  1. Put your package NAME in the line with the words applicationId "com.YOUR_PACKAGE_HERE"

  2. Synchronize your project (Ctrl+alt+v) and Build Again.

This is the code of the file buid.gradle (Module:app) that worked for me:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.YOUR_PACKAGE_HERE"
        minSdkVersion 24
        targetSdkVersion 17
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.google.firebase:firebase-database:9.6.1'

    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'

    compile 'com.google.firebase:firebase-crash:9.6.1'
    testCompile 'junit:junit:4.12'

    compile 'com.google.firebase:firebase-messaging:9.6.1'

    compile 'com.google.firebase:firebase-ads:9.6.1'


    compile 'com.google.firebase:firebase-auth:9.6.1'


    compile 'com.google.android.gms:play-services:9.6.1'

}
apply plugin: 'com.google.gms.google-services'
Gustavomcls
  • 1,655
  • 2
  • 12
  • 20
6

The same situation was with the previous versions. It's annoing that new versions com.google.android.gms libraries are always releasing before plugin, and it's impossible to use new version because is incompatible with old plugin. I don't know if plugin is now required (google docs sucks). I remember times when it wasn't. The only way is wait for new plugin version, or you can try to remove plugin dependencies, but as I said I'am not sure if gcm will work without it. What I know the main feature of 9.2.0 version is new Awareness API https://inthecheesefactory.com/blog/google-awareness-api-in-action/en, if you didn't need it, you can use 9.0.0 version without any trouble.

yaneq6
  • 151
  • 8
  • Ah, go figure. Since there is no documentation stating otherwise, I assumed newest versions would roll out with the required plugin. AFAIK, you do need the plugin to make GCM work, so I'm guessing this is a manual-check-for-update solution. – herrmartell Jul 01 '16 at 14:52
  • 1
    For sure @yaneq google docs sucks, got the same problem right now – Lutaaya Huzaifah Idris Oct 07 '16 at 12:57
5

Gustavomcls's solution to change com.google.* version to same version worked for me .

I change both dependancies to 9.2.1 in buid.gradle (Module:app)

compile 'com.google.firebase:firebase-ads:9.2.1'
compile 'com.google.android.gms:play-services:9.2.1'
Rahul Bagal
  • 220
  • 3
  • 7
2

open app/build.gradle from your app-module and rewrite below line after dependencies block. This allows the plugin to determine what version of Play services you are using

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

I got this idea from here. In this tutorial second point is saying that above plugin line be at the bottom of your app/build.gradle file so that no dependency collisions are introduced. Hope it will help you out.

Rahul Sharma
  • 12,515
  • 6
  • 21
  • 30
2

For Cordova OR Ionic Hybrid App

I have the very similar problem with my Ionic 1 Cordova Build after Integrating the Firebase Cloud Messaging ( FCM )

I fixed this issue by the following steps

So one fix will be: inside platforms/android open project.properties (Its a file ) , you will have something like this

cordova.system.library.1=com.google.android.gms:play-services-ads:+
cordova.system.library.2=com.google.firebase:firebase-core:+
cordova.system.library.3=com.google.firebase:firebase-messaging:+

Replace the

+

Sign with your target version number - like the following

cordova.system.library.1=com.google.android.gms:play-services-ads:9.0.0
cordova.system.library.2=com.google.firebase:firebase-core:9.0.0
cordova.system.library.3=com.google.firebase:firebase-messaging:9.0.0

Save the file

Then take build using

 ionic cordova run android

I hope this will work for everyone

sijo vijayan
  • 1,590
  • 1
  • 21
  • 34
  • This just changed the error. That is kind of good as I have been only receiving the same error even with thousands of solutions tried. – spaceman Feb 22 '18 at 20:02
2

Add this line at the bottom of the gradle.

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

because it the top it does not work.I was facing similar problem.

Mudassir Khan
  • 1,714
  • 1
  • 20
  • 25
1

if you have Firebase included also, make them of same version as the error says.

srlgrg
  • 71
  • 4
0

I didn't have an issue with this until I tried to use the Location Services, at which point I had to put the apply plugin: 'com.google.gms.google-services' at the bottom of the file, rather than the top. The reason being that when you have it at the top there are collision issues, and by placing it at the bottom, you avoid those issue.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
-1

Your target SDK might be higher than SDK of the device, change that. For example, your device is running API 23 but your target SDK is 25. Change 25 to 23.

trungduc
  • 11,926
  • 4
  • 31
  • 55