125

I upgraded my build.gradle file from

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

to

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

and now I am getting this error that I wasn't getting before.

Error:Failed to resolve: com.google.android.gms:play-services-measurement:9.0.0 enter image description here

enter image description here

Philip Herbert
  • 4,599
  • 2
  • 37
  • 40
  • 2
    Have you updated your Google Repository in the SDK Manager? – CommonsWare May 18 '16 at 23:47
  • Yes, I believe so. Google Repository = 26 – Philip Herbert May 18 '16 at 23:52
  • 1
    Hmmm... when I look at the POM for `play-services:9.0.0` in my SDK, I do not see `play-services-measurement` as a dependency, and there is no `9.0.0` of `play-services-measurement`. Are you manually requesting `play-services-measurement`? If not, try cleaning the project, or doing a command-line `gradle` build with the `--refresh-dependencies` switch, to try to get it to stop looking for `play-services-measurement`. On the whole, though, you are probably better off using the more-focused dependencies (the ones you have commented out) rather than the "kitchen sink" `play-services` one. – CommonsWare May 18 '16 at 23:59
  • 1
    1. I am not requesting the play-services-measurement at all, no where in my code. 2. I switched to "kitchen sink" play-service because of this error. 3. I may have to do this refresh which I have never done before. – Philip Herbert May 19 '16 at 00:05
  • I don't use the command line to often, how do I go about refreshing the dependencies via cmd line? – Philip Herbert May 19 '16 at 01:17
  • 1
    * What went wrong: A problem occurred configuring project ':app'. > Could not resolve all dependencies for configuration ':app:_debugCompile'. > Could not find com.google.android.gms:play-services-measurement:9.0.0. Searched in the following locations: https://jcenter.bintray.com/com/google/android/gms/play-services-measurement/9 .0.0/play-services-measurement-9.0.0.pom – Philip Herbert May 19 '16 at 01:49
  • 1
    Assuming that the answer below does not solve your problem, you need to determine what is trying to load that dependency (and, in particular, that version). `play-services` no longer requires it, as of 9.0.0, so something else must be asking for it. – CommonsWare May 19 '16 at 01:53

6 Answers6

246

This was found to fix the problem.

Update your classpath in project level gradle com.google.gms:google-services:2.1.0 to classpath com.google.gms:google-services:3.0.0

ziddi609
  • 29
  • 7
user3330522
  • 2,484
  • 1
  • 12
  • 2
  • 39
    If someone doesn't find it... this change must be made in the top level build.gradle.... this worked for me but then I got this error "Missing api_key/current_key object", so I had to apply this solution http://stackoverflow.com/a/37317752/50730 – Javier Torón May 19 '16 at 11:42
  • I get the old error "Attribute "orientation" has already been defined". Updated google-services classpath to 3.0.0. And enabled GCM and added Server API key tat is generated in google-services.json file. Could anybody help me ? – cgr May 20 '16 at 17:54
  • 1
    Now the error has changed to "Error:Execution failed for task ':app:processFreeDebugGoogleServices'. > Missing api_key/current_key object" ??? – LemonGentry May 26 '16 at 20:08
  • 5
    With respect, can someone explain exactly why this "fix" works? I find the quality of SO answers that just give a recommendation, without pointing to docs or core reasons for the original failure, to be barely helpful, and potentially lead to more confusion. – Tom Pace Jun 03 '16 at 18:57
  • still getting error Error:Could not find com.google.android.gms:play-services-maps:9.2.0. Required by: app_1:app:unspecified Search in build.gradle files – Rohit Mandiwal Jun 30 '16 at 10:31
  • For those that didn't get the point of update: it is into build.gradle of the project root (inside the dependencies tag), not the app one. :) – diogo Nov 01 '16 at 00:13
  • Hi I got com.google.gms:google-services:3.0.0 but why does my Android Studio still asks for 9.0.0 – Sheychan Nov 23 '16 at 07:51
  • I have version 3.0.0 but got the same error. I don't think this can fix the root of the issue. – J D Jan 27 '17 at 02:46
27

Required: Latest versions of Android Studio and Google Play Services

You can add the plugin to your project by updating your top-level build.gradle and your app-level build.gradle files as follows:

classpath 'com.google.gms:google-services:3.0.0'

Like

 // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenLocal()
    }
}

Now, you need to add a dependency for Google Play Services. Inside your app's build.gradle add:

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

Finally

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "// set Yours"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"


    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.google.android.gms:play-services-gcm:9.6.1'
    compile 'com.android.support:appcompat-v7:24.2.0'

}

apply plugin: 'com.google.gms.google-services'
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
11

GCM has been rebranded to Firebase Cloud Messaging (FCM), If you want to use com.google.android.gms:play-services:9.0.0 read this article FCM. Do this maybe work, modify your build.gradle file to use the plugin.

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:3.0.0'
  }
}
Kaushik
  • 6,150
  • 5
  • 39
  • 54
Saeed Darvish
  • 621
  • 6
  • 29
  • 4
    I got this error however `Error:Execution failed for task ':app:processDebugGoogleServices'. > Missing api_key/current_key object` – Shajeel Afzal May 19 '16 at 13:13
  • 7
    @ShajeelAfzal solve this problem by generate google-service.json https://developers.google.com/mobile/add – raditya gumay May 21 '16 at 15:58
  • I had to import my project into firebase console and regenerate the google-service.json file for it to work for me. Import your project into firebase and then click on 'manage' you can then download a new file if the above does not work for you – paul at stepupsoftware Jul 01 '16 at 10:17
  • Why **3.0.0**? Isn't that an old version. I believe we are on **9.4.0** already. – IgorGanapolsky Aug 22 '16 at 15:33
  • @IgorGanapolsky you dont neet to chagne 3.0.0 just update 9.2.1 to 9.4.0 – Saeed Darvish Sep 01 '16 at 06:24
  • 1
    @IgorGanapolsky version 3.0.0 is for gradle plugin, 9.4.0 is for library – alvinmeimoun Sep 17 '16 at 13:15
  • How do you update `com.google.android.gms` to version `9.2.0` in linux ?? SDK Manager is not showing any update, so I'll have to update manually – mrid Oct 14 '16 at 13:48
  • @mrid I'm from iran i just use proxy server and sdk manager show any updates to me.. if google developer limits your country just use proxy – Saeed Darvish Oct 15 '16 at 11:10
1

The easiest way I found is to use the latest version for all.

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
//apply plugin: 'com.google.gms.google-services' //Firebase
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
compile 'com.google.firebase:firebase-auth:10.2.6'
compile 'com.google.android.gms:play-services-auth:10.2.6' //10.2.6
compile 'com.google.firebase:firebase-core:10.2.6' // used for FCM
compile 'com.google.firebase:firebase-messaging:10.2.6' // used for FCM
testCompile 'junit:junit:4.12'
//  apply plugin: 'com.google.gms.google-services'

}

EXPLAINATION

apply plugin: 'com.google.gms.google-services' // Add this at bottom.

  • First, apply plugin: 'com.google.gms.google-services' // Add this at bottom.
  • Then, add these into dependencies

    compile 'com.google.firebase:firebase-auth:10.2.6' // make suere this is in latest version.

    compile 'com.google.android.gms:play-services-auth:10.2.6' //10.2.6 Latest

    compile 'com.google.firebase:firebase-core:10.2.6' // used for FCM

    compile 'com.google.firebase:firebase-messaging:10.2.6' // used for FCM

Suppose if you have firebase-auth 10.2.6 that is latest today 25, May 2017, But simultaneously you're using play-services-auth:9.0.0 or below than latest, then they both can't make the connection and show you the error.

I hope this helped.

0

I solved this tricky problem by changing the string in Gradle to

compile 'com.google.android.gms:play-services:9.0.0' //or latest version
Sattar
  • 2,453
  • 2
  • 33
  • 47
0

When changing play services to a version above 10.2.1 my dependencies started to fail resolving.

I found out that changing the following maven URL solved the issue:

maven { url 'https://raw.githubusercontent.com/onepf/OPF-mvn-repo/master/' }

to

maven { url 'https://github.com/onepf/OPF-mvn-repo/raw/master/' }

It might that the URL change avoids a cache it in gradle or maven and that resolves it.

Claus Holst
  • 901
  • 1
  • 8
  • 13