224

referencing the play-services via gradle stopped working for me - boiled it down - even the sample I used as a reference in the first place stopped working: https://plus.google.com/+AndroidDevelopers/posts/4Yhpn6p9icf

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':auth'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':auth:compile'.
      > Could not find com.google.android.gms:play-services:3.1.36.
        Required by:
            gpsdemos:auth:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.577 secs

I fear that just the version increased but that raises 2 questions: #1) what is the new one? #2) why is the old version gone?

ligi
  • 39,001
  • 44
  • 144
  • 244
  • 2
    You can see the available versions of Play Services here: C:\Users\USERNAME\AppData\Local\Android\android-studio\sdk\extras\google\m2repository\com\google\android\gms\play-services – Kuffs Sep 27 '13 at 10:03
  • 1
    Install the Google Repository in the SDK manager. – JJ_Coder4Hire Jun 25 '14 at 00:37

12 Answers12

465

Check if you also installed the "Google Repository". If not, you also have to install the "Google Repository" in your SDK Manager.

Also be aware that there might be 2 SDK installations - one coming from AndroidStudio and one you might have installed. Better consolidate this to one installation - this is a common pitfall - that you have it installed in one installation but it fails when you build with the other installation.

Example of how to access SDK Manager for Google Repository

CJBS
  • 15,147
  • 6
  • 86
  • 135
ligi
  • 39,001
  • 44
  • 144
  • 244
  • I do have it installed but still get this error. Do I need another repository specified in build.gradle next to mavenCentral()? – Brian Harris Jun 19 '13 at 07:17
  • 6
    no - just mavenCentral() - be aware that you might have 2 sdk locations - one is shipped with AndroidStudio - that is a common pitfall – ligi Jun 19 '13 at 07:46
  • I have only one studio. My deps include compile group: 'com.google.oauth-client', name: 'google-oauth-client', version: '1.15.0-rc' compile group: 'com.google.http-client', name: 'google-http-client-gson', version: '1.15.0-rc' compile group: 'com.google.api-client', name: 'google-api-client-android', version: '1.15.0-rc' compile group: 'com.google.apis', name: 'google-api-services-fusiontables', version: 'v1-rev25-1.15.0-rc' – Brian Harris Jun 19 '13 at 15:48
  • And the error is a bit different than yours Gradle: A problem occurred configuring project ':MyApplication3'. > Failed to notify project evaluation listener. > Could not resolve all dependencies for configuration ':MyApplication3:compile'. > Could not find com.google.android.google-play-services:google-play-services:1. Required by: MyApplication3Project:MyApplication3:unspecified > com.google.api-client:google-api-client-android:1.15.0-rc – Brian Harris Jun 19 '13 at 15:49
  • 6
    +1 but you mean: install "Google Repository" in your "Android SDK". – Benjamin Toueg Aug 18 '13 at 16:56
  • 1
    I hade to install both "Google Repository" and "Google Support Repository" to get it to work. +1 – Jan-Terje Sørensen Sep 03 '13 at 12:35
  • 1
    Thanks for the comment ligi. I didn't realize that Android studio started shipping an android sdk with it. Now I have 2 of them to manage :(. – harmanjd Sep 26 '13 at 18:55
  • @harmanjd if you are on an unix system you can link both sdk's ( ln -s is you friend ) - so you have only one to manage and save ( a lot of ) space – ligi Sep 26 '13 at 20:43
  • 4
    Weird that this piece of info isnt clearly stated elsewhere. But thanks for the help =) – Ted Dec 06 '13 at 10:31
  • Same issue I had `extra-android-m2repository` installed you need `extra-google-m2repository` installed, using the sdk manager does this. via cmd line you need to specify both. – Chris.Jenkins Apr 04 '14 at 09:43
  • I didn't realize that Android studio was using its own Android SDK! Thank you for pointing it out: I had been fighting the "Could not find any version that matches com.google.android.gms:play-services:+" for a while. – garph0 Apr 13 '14 at 08:02
  • 1
    I also had to install "Android Support Repository" in Extras on SDK Manager. – Yoo Matsuo Sep 21 '14 at 15:25
  • When I downloaded Android Studio it did not seem to come with the Android SDK, I probably just didn't understand it. At the time I simply plugged in my Android SDK that I was using with Eclipse and it worked fine. After your answer I realized I simply needed to go into my SDK manager and update and make sure Google Play Services was installed. – Caimen Jun 22 '15 at 20:17
  • Please edit your answer to include both the Google repository and the android support repository. A lot of us had to do this. – dessalines Sep 23 '15 at 16:43
  • I also got this error while using Visual Studio Cordova tools to build Android apps. Installing "Google Repository" from the "SDK Manager" did the trick. Thanks! – Phobis Apr 21 '16 at 22:52
  • It is so obvious but still I found a lot of wrong answers. This one was (among many) the one which solved my problem. – FtheBuilder Oct 02 '16 at 17:05
60

Just install Google Repository form your sdk manager and than restart Android Studio.

Khayam Gondal
  • 2,366
  • 2
  • 28
  • 40
37

In addition to installing the repository and the SDK packages one should be aware that the version number changes periodically. A simple solution at this point is to replace the specific version number with a plus (+) symbol.

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

Google instructions indicate that one should be sure to upgrade the version numbers, however adding the plus deals with the changes in versioning. Also note that when building in Android Studio a message will appear in the status line when a new version is available.

One can view the available versions of play services by drilling down on the correct repository path:

play-services repository path

References

This site also has instructions for Eclipse, and other IDE's.

ADS-Setup

Tommie C.
  • 12,895
  • 5
  • 82
  • 100
  • 2
    Changing my version to a '+' is what fixed it for me. Intellij was saying I should be using version 5.2.8, but the actual version that was available was 5.2.08 – jblack Aug 17 '14 at 04:07
  • 1
    Problem with this answer is that the currently available version of the play services is 4.4.52, meaning a user can't even upgrade to 5+. – withoutclass Aug 21 '14 at 17:23
16

I've been strugglin with this problem for hours till found this post. Just like @ligi said, some people have two SDK folders (Android Studio, which is bundled and Eclipse). The problem is that it doesn't matter if you downloaded the Google Play Services library on both SDK folders, your ANDROID_HOME enviroment variable must be pointing to the SDK folder used by the Android Studio.

SDK Folder A  (Used on Eclipse)
SDK Folder B  (Used on AS)

ANDROID_HOME=<path to SDK Folder B>

After change the path of this variable the error was gone.

Amaro
  • 501
  • 5
  • 10
8

I had the same problem because I had:

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

and I solved changing the version numbers for a '+'. so the lines has to be:

compile 'com.google.android.gms:play-services:+'
Shudy
  • 7,806
  • 19
  • 63
  • 98
  • This is a hack that could be detrimental in the future when you want a newer version of the library to be used but the compiler picks up an older version. You are basically telling gradle that you don't care which version of the Play services library your project uses. – Tjaart Oct 27 '14 at 13:17
  • 4
    The difficulty is that no matter where one digs, this environment does not lend itself to easily finding out what version is actually installed, all the Android docs are blatantly missing any clue of how to determine the version of "play" My SDK Manager tells me I simply have "26" (it's under "extras" not an API level), Some other window tells me it's 26.0.0. And I've tried these, and many other things version numbers... none of which work. So if you are concerned about people using this "hack", it is happening because they can't find the actual version number to use. – SpacemanScott Dec 08 '15 at 03:57
  • This simple trick solved this issue and I agree: documentation about what should be a simple choice if very frustrating and leads to errors. However this trick leads to another issue: MainActivity is not located and throws a ClassNotFound exception at build time – Pedro Santangelo Dec 14 '21 at 06:03
4

Adding this as a second reference because I had a similar problem..
I had to explicitly add '.aar' as a registered file type under the 'Archives' category in AS settings.

Shirkrin
  • 3,993
  • 1
  • 29
  • 35
3

If you already have Google Repository installed, make sure it's updated. I had to update my Google Repository and services. This was after I updated Android Studio.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
2

I added a new environment variable ANDROID_HOME and pointed it to the SDK (C:\Program Files (x86)\Android\android-studio\sdk) that is inside the installation directory of Android Studio. (Environment variables are a part of windows; you access them through the advanced computer properties...google it for more info)

user54636
  • 41
  • 4
1

I too had the same problem and resolved.

As per the above-mentioned solutions by others, I tried all the things and it does not solve my problem.

Even if you have two SDK locations, no need to worry about it and check whether your android home is set to Android studio SDK (If you have the Android repository and everything in that SDK location).

Solution:

  • Go to Your project structure
  • Select your modules
  • Click the dependance tap on the right side
  • Add library dependency
  • "com.google.android.gms:play-service:+"

I hope it will solve your problem.

1

I have the same question.

You should add some dependencies in build.gradle, just looks like this

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':libcocos2dx')
    compile 'com.google.firebase:firebase-ads:11.6.0'
// the key point line
    compile 'com.google.android.gms:play-services-auth:11.6.0'
}
ReadyShow
  • 21
  • 2
0

By mistake I added the compile com.google.android.gms:play-services:5.+ in dependencies in build script block. You should add it in the second dependency block. make changes->synch project with gradle.

therealrootuser
  • 10,215
  • 7
  • 31
  • 46
0

Personally this post helped me to solve this issue by moving the google() to the top of the repositories.

Yairopro
  • 9,084
  • 6
  • 44
  • 51