Introduction to Android App Bundle

Jitesh Mohite
4 min readOct 20, 2018

Google introduced the Android app bundle which helps in reducing the size of apk. They come up with a new upload format which includes all compile code and resources, but defers API generation and singing to google play. This optimization process called Dynamic Delivery, where apk generated based on the device configuration. Now we don’t require multiple apk to support multiple devices and even you don’t require any major code changes to achieve this.

There are four features which app bundle have:

1. Stop managing multiple APKs

2. Benefit from a smaller app

3. Deliver features on-demand, not at install

4. Enable modules to run instantly, without install

Dynamic Delivery with split apk.

Dynamic delivery with split apk is available from Android 5.0(API level 21) and higher. The split apk also includes compiling code, resources, and manifest. These split apk provides the functionality to split features in different apk, After which we can decide which apk to deliver first at installation time. Each Split apk contains its own code and resources, but it’s important to keep common code inside base apk.

This entire process is divided into three parts.

  • Base APK
  • Configuration APKs
  • Dynamic feature APKs

Base Apk: This apk contains all common code and resources required to other apk. When a user requests to download your app, this APK is downloaded and installed first. That’s because only the base APK’s manifest contains a full declaration of your app’s services, content providers, permissions, platform version requirements, and dependencies on system features.

Configuration APKs: Includes only native libraries and resources for a given device configuration. Specifically, this means optimizing the APK content based on the following:

  • Locale
  • Screen density
  • CPU architecture

Dynamic feature APKs: Each of these APKs contains code and resources for a feature of your app that is not required when your app is first installed. That is, using the Play Core Library, dynamic APKs may be installed on-demand after the base APK is installed on the device to provide additional functionality to the user.

The Android App Bundle Format:

Android app bundle generates the .aab file which we required to upload at google play to support dynamic delivery.

The Android App Bundle Format:

Android app bundle generates the .aab file which we required to upload at google play to support dynamic delivery.

Android app bundle is a zip archive it contains some resources that you already familiar with such as text with android resources, assets, and native libraries. The app bundle is purely a publishing format, so it cannot be directly installed on the device.

Getting started with the code

You will find the Android app bundle more useful when it deals with more complex real-world applications and has supported different languages, density images, architectures. Then you will get substantially reduced size of the apk.

Building Bundles

First, open app/build.gradle and add the following inside the android {} block:

bundle {
language {
enableSplit = true
}
density {
enableSplit = true
}
abi {
enableSplit = true
}
}

This ensures that language, density, and abi configuration splits are all enabled.

Now, you can build your App Bundle. Go to Build > Build Bundle(s) / APK(s) and select Build Bundle(s):

Bundles are stored in .aab format. You can see the generated .aab in your build directory. See app > build > outputs > bundle > debug > bundle.aab

Once you upload the bundle to Google Play, Play only installs the configurations required by the user device. This includes:

  • Only res values corresponding to the device locale. A user with the default language set to Japanese, for example, would get only the strings in values-jp, not all strings.
  • Only assets corresponding to the device screen density. For xxxhdpi device, this means only the contents of drawable-xxxhdpi are served, not the contents targeting other densities.
  • If a module has an x86 and an ARM CPU architecture, only the relevant native libraries for that architecture.

--

--

Jitesh Mohite

I am technology enthusiastic, want to learn things quickly and dive deep inside it. I always believe in developing logical things which makes impact on end user