Skip to content

Most visited

Recently visited

navigation

Set up your build for configuration APKs

You can reduce your app's APK size on each user's device by setting up your build for configuration APKs (config APKs for short). This places your app's DEX code and device-agnostic resources in one APK and each set of device-dependent native code and resources in separate APKs. Devices then request only the APKs needed to run your app. This allows you to reduce the downloaded size of your app by creating APKs that contain files for specific screen densities, ABIs, and/or languages.

Configuration APKs are similar to Multiple APKs, with a few important differences:

Prerequisites

Before you set up your build for configuration APKs, review the following steps to make sure your build is ready, and verify you have the tool configuration you need in Android Studio:

Set up your build for configuration APKs

To set up your build for configuration APKs based on languages, add a language block to the splits block of your feature module, and specify generatePureSplits = true in the android block. For more information about configuring the splits block, see Configure your build for multiple APKs.

android {
  ...
  generatePureSplits = true
  splits {
    abi {
      enable = true
    }
    density {
      enable = true
    }
    language {
      enable = true
      include “es-rMX”, ”zh”, “en”
    }
  }
}

Language values are in the format described in Providing Alternative Resources.

Serving configuration APKs

Unlike using Multiple APKs, developers do not define an ordering over multiple equivalent configuration APKs. So how does Play decide which to serve?

For ABI, Play chooses from among the compatible APKs using a fixed ordering that is the same for every device. That ordering is x86_64, x86, mips64, mips, arm64-v8a, armeabi-v7a, armeabi. For example, if a device supports both x86 and armeabi-v7a, and APKs are available for both, then the x86 APK will be served (along with the base).

For density, Play chooses the APK closest to the device’s density among those available.

Selection of APKs by language is more complicated.

Special concerns for language targeting

One might expect that Play tries to match the user’s locale exactly. If that’s en-GB, then maybe it serves an APK targeted to en-GB, if available, otherwise falling back to en. There would be two problems with that approach:

  1. There’s no requirement that a configuration APK has to contain translations of every string, just as there's no such requirement for a strings.xml file. It's acceptable (and even common) to add a language for just one string or a few strings. For example, en/strings.xml might contain “car” and “truck”, and en-rGB/strings.xml might contain just “lorry”. So, just as the necessary set of translations for any device might lie across multiple strings.xml files, those files may be contained in multiple configuration APKs.
  2. Android devices have widely varying fallback graphs. Android releases can change the fallback graph (see, for example, Language and Locale). Moreover, OEMs customize the fallback order. (For example, whether “zh” prefers “zh-TW” or “zh-CN” depends on the OEM.) Play doesn't always know what fallback order is used by the requesting device.

Play works around the problems by serving all the configuration APKs targeted to languages whose language subtag (the part before the dash) matches that of the user’s selected locale(s). This relies on the observation that fallback algorithms usually do not fall back across languages. Here's an example:

User’s locale is de-CH.
Available APKs are de, de-CH, de-AT, and fr.
Play will serve de, de-CH, and de-AT, but not fr.

Play also handles certain well-known cases where languages should be grouped together despite having mismatched language subtags, such as fil/tag.

The grouping is done by Play at serving time and requires no action on the part of the developer.

Troubleshooting and frequently asked questions

Known issues

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)