bundletool: Command-line tool to manipulate Android Application Bundles

The “bundletool” is a command-line tool developed by Google for manipulating Android Application Bundles (AAB). An Android Application Bundle is a publishing format introduced by Google that contains all the resources and code needed to build an Android app.

The “bundletool” command-line tool provides various functionalities for working with Android Application Bundles. Some of its key features include:

  • Build AAB: With the “bundletool build-apks” command, you can generate an Android Application Bundle (AAB) from your app’s compiled code and resources. This is useful for preparing an AAB for distribution or testing purposes.
  • Generate APKs: The “bundletool build-apks” command can also generate APKs (Android Package Files) from an Android Application Bundle (AAB). APKs are the installable files used for distributing Android apps. This feature allows you to create APKs that are optimized for specific devices or configurations.
  • Install APKs: The “bundletool install-apks” command enables you to install APKs or an Android Application Bundle (AAB) on connected devices or emulators. This is useful for testing or deploying the app on different target devices.
  • Extract APKs: The “bundletool extract-apks” command allows you to extract the APKs contained within an Android Application Bundle (AAB). This can be helpful for examining the individual APKs or extracting specific resources from the bundle.
  • Validate Bundle: The “bundletool validate-bundle” command validates the integrity and correctness of an Android Application Bundle (AAB). It checks if the bundle is well-formed and adheres to the required specifications.
  • Optimize APKs: The “bundletool optimize” command optimizes APKs by applying compression techniques and resource shrinking to reduce their size. This can help improve app performance and reduce download times for users.

The bundletool command-line tool provides flexibility and automation for handling Android Application Bundles. It is particularly useful for developers who want to customize the app distribution process, create optimized APKs, or perform advanced tasks related to Android app packaging.

To use bundletool, you typically need to have the bundletool package installed on your system. Once installed, you can execute various commands to perform operations such as building, generating APKs, installing APKs, extracting APKs, validating bundles, and optimizing APKs.

bundletool Command Examples

1. Display help for a subcommand:

# bundletool help subcommand

2. Generate APKs from an application bundle (prompts for keystore password):

# bundletool build-apks --bundle=/path/to/bundle.aab --ks=/path/to/key.keystore --ks-key-alias=key_alias --output=/path/to/file.apks

3. Generate APKs from an application bundle giving the keystore password:

# bundletool build-apks --bundle=/path/to/bundle.aab --ks=/path/to/key.keystore --ks-key-alias=key_alias –ks-pass=pass:the_password --output=/path/to/file.apks

4. Generate APKs including only one single APK for universal usage:

# bundletool build-apks --bundle=/path/to/bundle.aab --mode=universal --ks=/path/to/key.keystore --ks-key-alias=key_alias --output=/path/to/file.apks

5. Install the right combination of APKs to an emulator or device:

# bundletool install-apks --apks=/path/to/file.apks

6. Estimate the download size of an application:

# bundletool get-size total --apks=/path/to/file.apks

7. Generate a device specification JSON file for an emulator or device:

# bundletool get-device-spec --output=/path/to/file.json

8. Verify a bundle and display detailed information about it:

# bundletool validate --bundle=/path/to/bundle.aab

Summary

In summary, bundletool is a powerful command-line tool provided by Google for manipulating Android Application Bundles. It offers functionalities for building AABs, generating APKs, installing APKs, extracting APKs, validating bundles, and optimizing APKs. This tool empowers developers to efficiently manage and customize the packaging and distribution of Android apps.

Related Post