Posted by Doug Stevenson, Developer Advocate
Version 10.0.0 of the Google Play services client libraries, as well as the
Firebase client libraries for Android, will be the last version of these
libraries that support Android API
level 9 (Android 2.3, Gingerbread). The next scheduled release of these
libraries, version 10.2.0, will increase the minimum supported API level from 9
to 14 (Android 4.0.1, Ice Cream Sandwich). This change will happen in early
2017.
Why are we discontinuing support for Gingerbread and Honeycomb in Google
Play services?
The Gingerbread platform is almost six years old. Many Android developers have
already discontinued support for Gingerbread in their apps. This helps them
build better apps that make use of the newer capabilities of the Android
platform. For us, the situation is the same. By making this change, we will be
able to provide a more robust collection of tools for Android developers with
greater speed.
What this means for your Android app that uses Google Play services or
Firebase:
You may use version 10.0.0 of Google Play services and Firebase as you are
currently. It will continue to work with Gingerbread devices as it has in the
past.
When you choose to upgrade to the future version 10.2.0, and if your app
minimally supports API level 14 or greater (typically specified as
“minSdkVersion” in your build.gradle), you will not encounter any versioning
problems. However, if your app supports lower than API level 14, you will
encounter a problem at build time with an error that looks like this:
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 9 cannot be smaller than version 14 declared in library [com.google.android.gms:play-services:10.2.0]
Suggestion: use tools:overrideLibrary="com.google.android.gms:play_services" to force usage
Unfortunately, the stated suggestion will not help you successfully run your app
on older devices. In order to use Google Play services 10.2.0 and later, you
can choose one of the following options:
1. Target API level 14 as the minimum supported API level.
This is the recommended course of action. To discontinue support for API levels
that will no longer receive Google Play services updates, simply increase the
minSdkVersion value in your app’s build.gradle to at least 14. If you update
your app in this way and publish it to the Play Store, users of devices with
less than that level of support will not be able to see or download the update.
However, they will still be able to download and use the most recently published
version of the app that does target their device.
A very small percentage of all Android devices are using API levels less than
14. You can read more about
the current distribution of Android devices. We believe that many of these
old devices are not actively being used.
If your app still has a significant number of users on older devices, you can
use multiple APK support in Google Play to deliver an APK that uses Google Play
services 10.0.0. This is described below.
2. Build multiple APKs to support devices with an API level less than
14.
Along with some configuration and code management, you can build
multiple APKs that support different minimum API levels, with different
versions of Google Play services. You can accomplish this with build
variants in Gradle. First, define build flavors for legacy and newer
versions of your app. For example, in your build.gradle, define two different
product flavors, with two different compile dependencies for the components of
Play Services you’re using:
productFlavors {
legacy {
minSdkVersion 9
versionCode 901 // Min API level 9, v01
}
current {
minSdkVersion 14
versionCode 1401 // Min API level 14, v01
}
}
dependencies {
legacyCompile 'com.google.android.gms:play-services:10.0.0'
currentCompile 'com.google.android.gms:play-services:10.2.0'
}
In the above situation, there are two product flavors being built against two
different versions of the Google Play services client libraries. This will work
fine if only APIs are called that are available in the 10.0.0 library. If you
need to call newer APIs made available with 10.2.0, you will have to create a
compatibility library for the newer API calls so that they are only built into
the version of the application that can use them:
- Declare a Java interface that exposes the higher-level functionality you
want to perform that is only available in current versions of Play services.
- Build two Android libraries that implement that interface. The “current”
implementation should call the newer APIs as desired. The “legacy”
implementation should no-op or otherwise act as desired with older versions of
Play services. The interface should be added to both libraries.
- Conditionally compile each library into the app using “legacyCompile” and
“currentCompile” dependencies.
- In the app’s code, call through to the compatibility library whenever newer
Play APIs are required.
After building a release APK for each flavor, you then publish them both to the
Play Store, and the device will update with the most appropriate version for
that device. Read more about multiple
APK support in the Play Store.