Credits: developer.android.com

Android App Bundle Complete Guide

Mrudul Tora
The Startup
Published in
5 min readAug 16, 2020

--

Google introduced new app publishing format on play console known as Android App Bundle (.aab extension) and is now the official publishing format. It was introduced in Google I/O 2018 and by second half of 2021, all new apps submitted on play console must use this format instead of Android Package(.apk extension) .

What is Android App Bundle ?

An Android App Bundle is a publishing format that includes all your app’s compiled code and resources, and defers APK generation and signing to Google Play.

Google Play uses your app bundle to generate and serve optimized APKs for each device configuration, so only the code and resources that are needed for a specific device are downloaded to run your app. You no longer have to build, sign, and manage multiple APKs to optimize support for different devices, and users get smaller, more-optimized downloads.

It differs from APK in the manner that you can’t directly deploy it to a device and then use it. Rather, it is a publishing format that includes all your app’s compiled code and resources in a single build artifact.

Advantage of Android App Bundle

  • Smaller app size : Google Play automatically splits the apk into multiple apk’s that are optimized for each device configuration. This means users enjoy smaller app downloads without the unused code and resources needed for other devices. On average, apps published with app bundles are 20% smaller in size.
  • Customize features Delivery : This feature allows you to make the users firstly download and install the app. Then, you can later ask the users to download a particular feature. For example, a gaming may ask to install new levels or a camera app asking to download filters.
  • Relief from managing multiple APK’s : Previously, to build optimized apps, developers need to manage multiple apks of the same app with different version codes but same package name. It was hard and time-consuming to handle such situation (especially if you are a beginner or intermediate in Android). But, by using android app bundles this all is managed by Google Play and you need not to worry about it.

It also has other advantages like efficient app releases, faster build times and it also offer Google Play Instant experiences.

Building an Android App Bundle

This feature is available in Android Studio 3.2 or later, Unity 2018.3 & 2017.4.17, and Cocos Creator 2.0.9 or later.

  • Firstly, include the following code in your build.gradle(Module:app) in android{} block.
bundle {
language {
enableSplit = true
}
density {
enableSplit = true
}
abi {
enableSplit = true
}
}
  • Then, go to Build > Build Bundle(s)/APK(s) and select Build Bundle(s).

This will generate a app-debug.aab file. (Android app bundle uses .aab extension).

Different types of Split apks :

A fundamental component of serving optimized applications is the split APK mechanism available on Android 5.0 (API level 21) and higher. Split APKs are very similar to regular APKs — they include compiled DEX bytecode, resources, and an Android manifest. However, the Android platform is able to treat multiple installed split APKs as a single app.

  • Base APK : This APK contains code and resources that all other split APKs can access and provides the basic functionality for your app. When a user requests to download your app, this APK is downloaded and installed first.
  • Configuration APKs: Each of these APKs includes native libraries and resources for a specific screen density, CPU architecture, or language. When a user downloads your app, their device downloads and installs only the configuration APKs that target their device. Each configuration APK is a dependency of either a base APK or feature module APK. That is, they are downloaded and installed along with the APK they provide code and resources for.
  • Feature module APKs: Each of these APKs contains code and resources for a feature of your app that you modularize using feature modules. You can then customize how and when that feature is downloaded onto a device.
Dependency tree for an app served using split APKs (image credit : developer.android.com)

Important: For devices running Android 4.4 (API level 20) and lower, Google Play automatically serves a single APK that’s optimized for the device’s configuration.

Testing the app with Google Play Console (Internal Test Track) :

Uploading an app on Play Console requires sigining of apk. So, for that, follow the steps given below :

  • Select Build > Generate Signed Bundle/APK from the menu bar. In the Generate Signed Bundle or APK dialog, select Android App Bundle and click Next.
  • In the Module dropdown menu, select the base module of the app you want to generate an app bundle for.
  • Provide information for an existing key and keystore, or create a new one. This is the same type of key and keystore information you provide when building a signed APK.
  • If you want Android Studio to also save your signing key as an encrypted file, check the box next to Export encrypted key. To be able to upload your app bundle and take advantage of Dynamic Delivery, you need to upload this encrypted file to the Play Console and enroll in app signing by Google Play.
  • Click Next and provide a Destination Folder for your app bundle. Select the Build Type and flavors that you want to generate app bundles for.
  • Click Finish.

Now , we can upload this app bundle on play console. To upload on Play Console (Internal Test Track) follow this tutorial.

Testing app bundle using bundletool :

To generate an APK set for all device configurations your app supports from your app bundle, use the bundletool build-apks command

$ bundletool build-apks --bundle=<path to .aab> --output=<out.apks>

Only two arguments are required,

  • The path to the .aab file and,
  • The directory where the generated apks are stored.

Now you can run build-apks.

WARNING: The APKs won't be signed and thus not installable unless you also pass a keystore via the flag --ks.$ bundletool build-apks --bundle=/MyApp/my_app.aab --    output=/MyApp/my_app.apks
--ks=/MyApp/keystore.jks
--ks-pass=file:/MyApp/keystore.pwd
--ks-key-alias=MyKeyAlias
--key-pass=file:/MyApp/key.pwd

To deploy your app from an APK set, use the install-apks command and specify the path of the APK set

bundletool install-apks --apks=/MyApp/my_app.apks

I hope this article will help you to get through Android App Bundles.

--

--

Mrudul Tora
The Startup

Android @ Mercari | 250K+ Installs on Google Play Store