Basic about Android App Bundle

Tram Ho

Written by: Tran Thanh Nghia

1. Introduction

Android App Bundle is a new format to upload to Google Play. Android App Bundle includes all source code and resources but not yet created APK and has not been signed by the keystore.

This new model for packaging for Google Play is called Dynamic Delivery . Dynamic Delivery will use the app bundle to receive and then create and optimize the APK suitable for each android device. Users now need only download the source code and resources needed to run the app.

Now developers won’t need to build, sign apps, and manage different devices; Users will receive an app with smaller and more optimal capacity.

In addition, you can add Dynamic Feature Modules to the project and add in app bundle. These modules will help you decide which parts are not added when the new user first installs. Using the Play Core Library makes it possible for applications to download the modules needed for devices via Dynamic Delivery.

2. Installation

Prerequisite to build app bundle must use Android Studio 3.2 and above.

Then you create a normal Android project. As a result, when running, it will display “Hello, World!” On the screen.

For Android Studio 3.2 and above, there will be 2 build modes as follows:

  • For Build APK , you already know. All source code and resources will be packaged into an apk file. And of course will be signed by your keystore.
  • For Build Bundle , you will export the file in .aab format (Android App Bundle) in app> build> outputs> bundle> debug> app.aab

When you upload this .aab file to Google Play, google play will only install the corresponding resource apk for that device.

Corresponding Resource includes:

  • Only contain res values by locale : For example, users who set the default Japanese language will only get values-jp.
  • Only containing assets according to the density of devices: For example, the screen is of xxxhdpi type, only drawable-xxxhdpi will be installed on the machine.
  • If the module supports x86 and ARM CPU architectures, installing the device will only install libraries according to the CPU architecture on that device.

Specify the separated resource

Open app / build.gradle and add the following to android {}

Note: all values ​​are set to true by default. So this paragraph will not be necessary if there is no change.

How does Dynamic Delivery divide APK?

About Dynamic Delivery will only work for Android 5.0 (API 21) and above. Dynamic Delivery will help Google Play divide the corresponding apk types to suit each user’s device.

When divided like this will be classified under 3 following forms:

Base APK

Will contain the code and resources that other decompiled apk can access and provide the basic functions to use. When the user downloads the app, this apk type will always be downloaded to the device.

Configuration APKs

Include only specialized libraries and resources for each type of devices:

  • Locale
  • Screen density
  • CPU architecture

Dynamic feature APKs

These are components that are not required to install the app for the first time but may also be downloaded and installed later.

For Android 4.4 (API 19) or below

Because Android 4.4 or below is not supported by App Bundle, Google Play will pack all source code and resources into 1 apk. This way is true of the traditional method so far.

Since Android under 4.4 will download all of them once, for Dynamic Features Modules will also be downloaded together (while Android 5.0 and above, Dynamic Features Modules load later). So you need to pay attention to a few configs in the following link to best support Dynamic feature modules

3. Android App Bundle structure (.aab)

In the picture below, the blue part (drawable, values, lib) is the part for Google Play to create config for APK for each module.

Read more in: https://developer.android.com/guide/app-bundle/#aab_format

4. Test run Android App Bundle

Android App Bundle serves for Google Play to pack better apk. So the easiest way to test is to upload the .aab file to Play Console for testing.

But there is another way you can test it using bundletool

Use bundletool

Please download the jar file in the following link https://github.com/google/bundletool/releases The latest version is 0.9.0. And all the personnel you have to install java then run the jar file

After downloading, you will get the file bundletool-all-0.9.0.jar .

The syntax to build a .aab file into .apks as follows: (note apks, not apk)

Note: the following terminal commands I am executing on macos. So on a different operating system will be a little different.

Step 1: Build file .aab

Go to Android Studio to build a .aab file

and the folder will be

Step 2: build .aab into .apks

Now you will get the file out.apks

Step 3: Extract the file .apks into apk

Create a folder to contain the decompression file

Extract the file apks into the apks directory:

The running results will be as follows:

The apks directory will look like this:

Inside:

  • splits is the folder containing the compressed apk
  • toc.pb (* .pb stands for Module Protocol Buffer): to define individual configurations corresponding to any apk in the splits folder

5. Conclusion

Here you understand how basically the Android App Bundle. To better understand how to create Dynamic Feature, please refer to the following example link:

https://github.com/googlesamples/android-dynamic-features

Good luck!

Share the news now

Source : Viblo