24

Android SDK Manager notified me this morning that there was a new Google Play Services release to download: revision 18. So how do I find the corresponding long version number to put in my build.gradle file? All my test devices are running version 5.0.84, so I tried updating

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

to

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

But that resulted in an error:

Gradle 'MyApp' project refresh failed: Could not find com.google.android.gms:play-services:5.0.84. Required by: {my app} Gradle settings

I'm running Android Studio 0.5.2 and building for API19 (I haven't upgraded to Android L/API20 yet): maybe that's the issue? But in general, how do you match a revision number shown in SDK Manager (e.g. 18) with a version code for build.gradle (e.g. 5.0.84)?

Here's my full build.gradle in case it helps:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    // Avoid "Duplicate files copied in APK" errors when using Jackson
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    // Was "compile 'com.android.support:support-v4:+'" but this caused build errors when L SDK released
    compile 'com.android.support:support-v4:19.1.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Support for Google Cloud Messaging
    // Was "compile 'com.android.support:appcompat-v7:+'" but this caused build errors when L SDK released
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services:5.0.84'

    // Jackson
    compile 'com.fasterxml.jackson.core:jackson-core:2.3.3'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.3.3'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.3'
}
Mark Whitaker
  • 8,465
  • 8
  • 44
  • 68

2 Answers2

40

OK, I haven't quite managed to find a mapping of one to the other, but I've managed the next best thing which is to see a list of Play Services long version numbers installed on my development machine.

For Windows, it's in [android-sdk]\extras\google\m2repository\com\google\android\gms\play-services (where [android-sdk] is the path to your Android SDK folder).

On a Mac, it's inside the Android.app package: browse to sdk/extras/google/m2repository/com/google/android/gms/play-services

The latest version on my machine was 5.0.77 (not 5.0.84), and putting that in my build.gradle worked fine.

Here's the kind of thing you should see at that location:

Google Play Services versions on Windows

Google Play Services versions on OSX

Mark Whitaker
  • 8,465
  • 8
  • 44
  • 68
  • 3
    Yes i just started porting over to Android Studio and this is kind of confusing as i couldn't find a way to browse through the version numbers (Yes i'm spoilt by auto complete). Howevery replacing the version number with a '+' should always pick the latest version. – Suau Aug 05 '14 at 08:51
  • On MacOSX after one verifies that the correct packages are installed using the SDK Manager in Android Studio, one can verify that the repository package is installed and find this directory structure within the Android Studio package contents below the sdk directory. The path structure is then the same. Also confirmed that replacing the version number with a plus will remove current and future issue. – Tommie C. Aug 11 '14 at 01:08
  • @Su-AuHwang just using `+` could have unintended effects. Better do like `alias installed-play-services="ls ${ANDROID_HOME}/extras/google/m2repository/com/google/android/gms/play-services/"` to easy check what you have installed instead. – Victor Häggqvist Aug 13 '14 at 17:09
  • @VictorHäggqvist I usually hardcode the version number and use the `+` only on sample projects or early in development. My main complain here is that autocomplete for artifacts and version numbers is broken. It's weird because it does already work fine in IntelliJ's gradle projects. – Suau Aug 14 '14 at 11:41
3

What I did in my project was download google play service and open the project structure > dependencies tab and click on the plus button and choose google play service. I dont have to care about the version anymore

Jamie Nhu
  • 41
  • 2
  • 2
    This resolved my error. I removed 5.0.77 and added 5.0.88. Here's a [screenshot](http://cl.ly/image/0O1f0b0G0j21) of the Project Structure window. – nicksuch Sep 28 '14 at 21:08