Skip to content

A Quick Guide to bundletool

Android, bundletool2 min read

When it comes to distributing Android apps, one powerful tool in the developer's arsenal is bundletool. Bundletool is a command-line utility provided by Google that helps developers build, manipulate, and optimize Android App Bundles. In this guide, we will explore the key features of bundletool and walk through some practical examples using Kotlin.


Before diving into the examples, let's cover the installation process for bundletool:

  1. Download the latest version of bundletool from the official GitHub repository.
  2. Extract the downloaded archive.
  3. Add the bundletool executable to your system's PATH variable.

Once you have bundletool set up, you're ready to start leveraging its capabilities.

Example 1: Building an Android App Bundle

To create an Android App Bundle using bundletool, follow these steps:

  1. Ensure that you have the necessary artifacts, including the app's APK file and a .aab file containing the module definition (such as base.aab).

  2. Open a terminal window and navigate to the directory containing the artifacts.

  3. Run the following command to generate the Android App Bundle:

    1bundletool build-apks --bundle=base.aab --output=myapp.apks

    This command takes the base.aab file as input and produces an .apks file named myapp.apks, which contains the app bundle.

  4. Extract the APKs from the generated .apks file using the following command:

    1bundletool extract-apks --apks=myapp.apks --output-dir=extracted_apks

    The extracted APKs can now be used for various purposes, such as testing and distribution.

Example 2: Optimizing an App Bundle

Bundletool provides optimization techniques to reduce the size of your Android App Bundle. Let's explore one such example:

  1. Assuming you have an existing .apks file named myapp.apks, execute the following command to optimize it:

    1bundletool optimize --apks=myapp.apks --output=myapp_optimized.apks

    This command applies optimization algorithms to the input .apks file and generates a smaller, optimized .apks file named myapp_optimized.apks.

  2. Extract the optimized APKs from the new .apks file:

    1bundletool extract-apks --apks=myapp_optimized.apks --output-dir=optimized_apks

    The extracted APKs now reflect the optimized version of your app bundle.

Example 3: Verifying an App Bundle

Bundletool allows you to verify the integrity and structure of your app bundle. Here's how to perform verification:

  1. Execute the following command to validate an .apks file:

    1bundletool validate --apks=myapp.apks

    This command performs various checks on the app bundle, ensuring that it is correctly structured and does not contain any errors.

  2. If the validation process completes without any issues, you'll see a success message indicating that the app bundle is valid.

These were just a few examples to showcase the capabilities of bundletool. It offers many more features and options that can significantly streamline your Android app development and distribution workflows.

In Summary

In this guide, we explored bundletool, a powerful command-line utility for managing Android App Bundles. We covered the installation process and walked through practical examples demonstrating how to build an app bundle, optimize its size, and perform verification. By harnessing the power of bundletool, you can enhance your Android app development process and ensure efficient app delivery to your users.