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 {}
1 2 3 4 5 6 7 8 9 10 11 | bundle { language { enableSplit = true } density { enableSplit = true } abi { enableSplit = true } } |
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)
1 | bundletool build-apks --bundle = <path to .aab> --output = <out.apks> |
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
1 | ./app/build/outputs/bundle/debug/app.aab |
Step 2: build .aab into .apks
1 | java -jar bundletool -all-0.9.0.jar build-apks --bundle = MyApplication / app / build / outputs / bundle / debug / app.aab --output = out.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
1 | mkdir apks |
Extract the file apks into the apks directory:
1 | unzip out.apks -d apks |
The running results will be as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | Archive: out.apks extracting: apks / splits / base-hdpi.apk extracting: apks / splits / base-ldpi.apk extracting: apks / splits / base-mdpi.apk extracting: apks / splits / base-xhdpi.apk extracting: apks / splits / base-xxhdpi.apk extracting: apks / splits / base-xxxhdpi.apk extracting: apks / splits / base-da.apk extracting: apks / splits / base-ca.apk extracting: apks / splits / base-tvdpi.apk extracting: apks / splits / base-ka.apk extracting: apks / splits / base-fa.apk extracting: apks / splits / base-ja.apk extracting: apks / splits / base-nb.apk extracting: apks / splits / base-ta.apk extracting: apks / splits / base-pa.apk extracting: apks / splits / base-be.apk extracting: apks / splits / base-de.apk extracting: apks / splits / base-ne.apk extracting: apks / splits / base-te.apk extracting: apks / splits / base-af.apk extracting: apks / splits / base-bg.apk extracting: apks / splits / base-fi.apk extracting: apks / splits / base-hi.apk extracting: apks / splits / base-th.apk extracting: apks / splits / base-si.apk extracting: apks / splits / base-kk.apk extracting: apks / splits / base-vi.apk extracting: apks / splits / base-sk.apk extracting: apks / splits / base-mk.apk extracting: apks / splits / base-uk.apk extracting: apks / splits / base-ml.apk extracting: apks / splits / base-gl.apk extracting: apks / splits / base-el.apk extracting: apks / splits / base-nl.apk extracting: apks / splits / base-pl.apk extracting: apks / splits / base-sl.apk extracting: apks / splits / base-am.apk extracting: apks / splits / base-km.apk extracting: apks / splits / base-tl.apk extracting: apks / splits / base-kn.apk extracting: apks / splits / base-in.apk extracting: apks / splits / base-bn.apk extracting: apks / splits / base-lo.apk extracting: apks / splits / base-ko.apk extracting: apks / splits / base-mn.apk extracting: apks / splits / base-ro.apk extracting: apks / splits / base-sq.apk extracting: apks / splits / base-ar.apk extracting: apks / splits / base-mr.apk extracting: apks / splits / base-hr.apk extracting: apks / splits / base-fr.apk extracting: apks / splits / base-tr.apk extracting: apks / splits / base-or.apk extracting: apks / splits / base-sr.apk extracting: apks / splits / base-as.apk extracting: apks / splits / base-ur.apk extracting: apks / splits / base-bs.apk extracting: apks / splits / base-cs.apk extracting: apks / splits / base-es.apk extracting: apks / splits / base-is.apk extracting: apks / splits / base-ms.apk extracting: apks / splits / base-et.apk extracting: apks / splits / base-it.apk extracting: apks / splits / base-lt.apk extracting: apks / splits / base-pt.apk extracting: apks / splits / base-eu.apk extracting: apks / splits / base-gu.apk extracting: apks / splits / base-ru.apk extracting: apks / splits / base-lv.apk extracting: apks / splits / base-hu.apk extracting: apks / splits / base-zu.apk extracting: apks / splits / base-sv.apk extracting: apks / splits / base-iw.apk extracting: apks / splits / base-sw.apk extracting: apks / splits / base-hy.apk extracting: apks / splits / base-ky.apk extracting: apks / splits / base-my.apk extracting: apks / splits / base-uz.apk extracting: apks / splits / base-az.apk extracting: apks / splits / base-en.apk extracting: apks / splits / dynamic_feature-ldpi.apk extracting: apks / splits / base-zh.apk extracting: apks / splits / dynamic_feature-mdpi.apk extracting: apks / splits / dynamic_feature-hdpi.apk extracting: apks / splits / dynamic_feature-xhdpi.apk extracting: apks / splits / dynamic_feature-xxxhdpi.apk extracting: apks / splits / dynamic_feature-xxhdpi.apk extracting: apks / splits / dynamic_feature-tvdpi.apk extracting: apks / splits / dynamic_feature-master.apk extracting: apks / splits / base-master.apk inflating: apks / toc.pb |
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!
Source : Viblo