Android App Bundles: Getting Started

See how to use App Bundles to reduce the size of the app your user downloads to their device, saving them precious data and storage! By Arturo Mejia.

Leave a rating/review
Download materials
Save for later
Share

The App Bundle is a new delivery format for Android apps that helps to deliver an optimized version of your APK by just including what your users need, reducing your app size and making your users happier. :]

Normally, when users download your app, they get what is called a universal APK. This is a file that contains all resources for all device configurations, like images, strings, layouts, and more. Users will not need all of them, which wastes space and leaves less room for apps or games. 😿

With App Bundles, your users will receive a special version of your APK that only includes the language, screen density and resources they need per unique user configuration.

Imagine one of your users has selected English as their default language, and that their device supports extra-extra-high-density (aka xxhdpi). Using App Bundles, the Google Play Store is only going to download an APK file with value-en/strings.xml and xxhdpi resources, reducing the required space and cost of the app.

Note: This tutorial assumes you’re already familiar with the basics of Android development. If you are completely new to Android development, read through our Beginning Android Development tutorials to familiarize yourself with the basics. Other pre-requisites include knowledge of using bash/Terminal, Gradle, and a developer account on the Google Play Console.

How Are App Bundles Useful?

Space is one major reason why a user will install or uninstall your app. When users download a new app, they have to take two things into consideration: data and storage consumption.

If your app is too big, users may have to uninstall one or more other apps in order to install yours.

Out of memory

Another trade-off is how much data your app is going to cost them, depending on their data plan. Users often have limited mobile data plans, which means that downloading your app may put users in a tricky situation. They will need to decide what’s more important: streaming videos or downloading your app.

You don’t want to be the app that increases their phone bill, right?

Data usage

Having a light APK will help you to attract new users to your app and keep existing users. :]

Note: To use App Bundles, you need to install Android Studio 3.2 or higher. If you don’t have it, please download it before continuing.

Getting Started

CountOnMe is an app that displays a number from 1 to 10, every time you swipe. You’re going to use it to see how to use App Bundles in practice, by generating and evaluating the content of different APKs.

Count on me demo

Download the CountOnMe project using the Download Materials button at the top or bottom of this tutorial. Open the project in Android Studio 3.2 or later by selecting Open an existing Android Studio project on the Android Studio welcome screen:

Open an existing Android Studio project

There is no final project for this tutorial, since you’ll simply use CountOnMe to explore the App Bundle tools in Android Studio.

Before continuing with the tutorial, take a look at the project.

Exploring the CountOnMe Structure

The source code is structured as follows:

CountOnMe project structure

  • MainActivity.kt
    This is the entry point of the app.
  • values
    default resources in English strings, dimens etc .
  • values-es
    default resources in Spanish strings, dimens etc .
  • values-fr
    default resources in French strings, dimens etc .

As you can see in the above image, there are many more files that weren’t mention for brevity. But the main idea is that you can see the different resources that the app has. When you use App Bundles, you’re going to generate different APK versions that only include some of these resources.

Generating an App Bundle

App Bundle is a new format called .aab (Android App Bundle), that you upload to the Play Store instead of the traditional apk. With this new format, the Play Store will generate many different variations of your APK, depending on your user’s device configuration.

App Bundles take advantage of a concept called split APK. As its name suggests, a split APK is similar to a normal .apk. The difference is that a split APK file can be broken into separate small pieces, one containing the base code and other small APKs containing the app resources that can be installed later.

The beauty of splits is that the Android operating system treats the app as a whole, and each split is a small fraction that can be added independently. It’s like one app with small Lego blocks to add on.

To see how an App Bundle is structured, you’ll generate one for the CountOnMe app.
Go to BuildBuild Bundle(s) / APK(s)Build Bundle(s) in the Android Studio menu.

Generate App Bundle

Android Studio will show you a prompt for where to find the file. Press locate to open the file location in your file system viewer, e.g., the Finder on macOS.

Locate app bundle

Since an .aab file is just a compressed file, uncompress it to take a look at its content.
App bundle file

In this case, you’ll use the tool unzip, but you can use any similar tool you like. Open Terminal and navigate to the directory containing the app.aab file. Run the following.

unzip app.aab

Alright, now you can see the structure of an .aab.

App bundle contents

  • base/, feature1/, and feature2/
    Top level folder that contains each module of your app. In the case of CountOnMe, you only have one base directory, because you just have one module. The base directory always contains the main module of your app. Each dynamic feature module will have it’s own feature directory.
  • BUNDLE-METADATA/
    Metadata files that may include ProGuard mappings and the list of your app’s DEX files. This directory is only going to be available when proguard is enabled.
  • Module Protocol Buffer (*.pb) files
    Provides metadata that describes the contents of each app module to the Play Store. For instance, BundleConfig.pb provides information about the bundle itself, like which version of the build tools were used to build the App Bundle.
  • dex
    Contains the DEX files for each module in a separate directory.
  • res, lib, and assets
    These folders are used in the same way as a typical APK, except that for an App Bundle, they’re used by Google Play to package only the files that satisfy the target device configuration.
  • root
    This directory stores files that are later relocated to the root of the APK(s) that include the corresponding module.

The only thing you have to do to use an App Bundle is create an .aab and upload it to the Google Play Store. The Play Store will handle everything from creating multiples version of your APK, to selecting the right one for your users.