jul
jul

Reputation: 37474

How to manage Google Play Services update in an Android app?

I'm kind of lost about how to manage Google Play Services in an app.

The doc specifies that the latest version of play-services should be downloaded and that it should be set in gradle.build with the version number, e.g.

dependencies {
    //...
    compile 'com.google.android.gms:play-services:6.1.+'
}

Then it's explained that:

Be sure you update this version number each time Google Play services is updated.

What does it mean? Does it mean that every time a new version is released it should be updated in the app and its version number reset in the build.gradle (meaning that a new apk should be done everytime, which sounds crazy)?

It's also specified that the following tag should be added in the manifest:

<meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version" />

Why, there is no explanation?

Then I found out in that SO answer that Google Play Services version should be check in the app using something like

// Check status of Google Play Services
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

// Check Google Play Service Available
try {
    if (status != ConnectionResult.SUCCESS) {
    GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
    }
} catch (Exception e) {
    Log.e("Error: GooglePlayServiceUtil: ", "" + e);
}

and that would open a dialog to download the latest version in case the one in the app is not up-to-date.

But what does it do? Does it replace the lib set when the apk is built? In that case, how does it manage the version number set in the build.gradle?

Anybody could help clarifying this?

Upvotes: 3

Views: 1987

Answers (1)

zapl
zapl

Reputation: 63955

Does it mean that every time a new version is released [..] a new apk should be done

No. When you release a new version of your app, check for updates of that library since it may have fixed something. But you can keep using old versions if you're lazy and don't check for new versions, they won't stop working all of a sudden.

<meta-data ... Why, there is no explanation?

That is information used by GooglePlayServicesUtil and the play services framework installed on your phone to make sure that everything works fine even when your app has an older version of the library in use. The dialog is an easy way to tell the user to do so.

.. that would open a dialog to download the latest version in case the one in the app is not up-to-date. But what does it do?

There are two components required on a device to use the google services.

1) The Play Services Framework App.

https://play.google.com/store/apps/details?id=com.google.android.gms

It provides services that manage login information at google for you for example. The user has to install and update the version via play store when required by an app.

2) The Play Services Library.

That's what you ship with your app and all it does is to provide classes that use services provided by above app. You have to update the library via gradle.

The library requires a certain version of the app. So to check whether there is that app installed and it has at least the required version you do the GooglePlayServicesUtil part.

It is no problem when the app is never than your library. It will know based on <meta-data how to deal with old versions.

Upvotes: 4

Related Questions