Road to App Bundle and Bundletool

What is a App Bundle

An Android App Bundle is a new upload format that includes all your app's compiled code
 and resources, but defers APK generation and signing to Google Play. ... So, users can download apps
 as large as 500MB and, with dynamic delivery, all of that storage is used for only the code and 
resources they need to run the app.
source: https://developer.android.com/guide/app-bundle
Google is actively trying decrease the sizes of apks, first with Multiple APK support. But this was not really a success as most developer should didn't use this feature.

With App Bundle it's automatically executed on the background when the App Bundle is uploaded to the play store. This feature is called Dynamic Delivery.For each language, density and ABI (Application Binary Interface) an apk is generated with only the required content. This results in smaller apk's, which result in faster download times and less memory usage.

More information about why to use App Bundles can be found on the Android technology page.

Android app bundle logo

How to create an app bundle

There are several ways to create an App Bundle.

From Android Studio Build => Build bundle(s) / APK(s) => Build Bundle(s)
Android Studio build app bundle

From command line for CI environments to build a debug/release App Bundle:
            gradlew bundleDebug
            gradlew bundleRelease
        
The generated App Bundle is located in \app\build\outputs\bundle\app.aab


Bundletool from command line

Now you have an App Bundle, But how can you run it on an Android Device?
To run it on an Android device it needs to converted towards an APK with bundletool.

Currently bundletool isn't available from the Android sdk, but it is available through the GitHub repository release page. Download the latest bundletool-all-x.x.x.jar, when writing version 0.9.0 was the newest release.

The tool is a .jar file, the easiest way to use the Bundletool from command prompt, is to place the downloaded .jar file in the android sdk platform-tools folder.

Also create a new file bundletool.bat and place it also inside the android sdk platform-tools folder
We assume that folder platform-tools is already added to the $PATH environment variables
Let's verify bundletool works as expected. Run bundletool version in command prompt.
When the version number is printed, you have successfully added bundletool to you're default tools set.
cmd bundletool version

How to install the App Bundle on an Android device?

The App Bundle can't be installed directly to an Android device. First it needs to be converted towards an .apks which can be installed on an Android Devices.

When the Android device is locally connected a optimized apk can be created:
bundletool build-apks --bundle=app.aab --output app.apks --connected-devices

When you are working with multiple devices you can create a device spec:
bundletool get-device-spec --output=<device>.json

This device spec can be used to generate a .apks for support the specific device(s):
bundletool build-apks --bundle=app.aab --output app.apks --device-spec=<device>.json

The generated apks can be installed on the Android device:
The tool extract the .apks and generate .apk which are installed on the connected devices:
bundletool install-apks --apks=app.apks

Links

  • https://developer.android.com/platform/technology/app-bundle
  • https://developer.android.com/guide/app-bundle
  • https://developer.android.com/studio/command-line/bundletool
  • https://github.com/google/bundletool
With this road to App Bundle you've learned to create and use the App Bundle.

Thank you for reading this article, If you liked the article, help others find this article by sharing it.

Reacties

Populaire posts van deze blog

Android-x86 virtual machine configuration tips

Android and SonarQube with code coverage

Setup SonarQube with Docker