How to use the command `bundletool dump` (with examples)

How to use the command `bundletool dump` (with examples)

Bundletool is a command-line tool provided by Android Studio that allows manipulation of Android Application Bundles. It provides various subcommands to extract information from the bundle files.

Use case 1: Display the AndroidManifest.xml of the base module

Code:

bundletool dump manifest --bundle=path/to/bundle.aab

Motivation: When developing Android applications, it is often necessary to check the content of the AndroidManifest.xml file. By using this command, developers can easily view the contents of this file without having to manually decompile the APK.

Explanation:

  • bundletool dump manifest is the command to extract the AndroidManifest.xml file.
  • --bundle=path/to/bundle.aab specifies the path to the Android Application Bundle file.

Example output:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.app" android:versionCode="1" android:versionName="1.0">
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name">
    ...
    </application>
</manifest>

Use case 2: Display a specific value from the AndroidManifest.xml using XPath

Code:

bundletool dump manifest --bundle=path/to/bundle.aab --xpath=/manifest/@android:versionCode

Motivation: Extracting specific values from the AndroidManifest.xml file using XPath can be helpful when automating build processes or performing data analysis on the bundle files.

Explanation:

  • bundletool dump manifest is the command to extract the AndroidManifest.xml file.
  • --bundle=path/to/bundle.aab specifies the path to the Android Application Bundle file.
  • --xpath=/manifest/@android:versionCode provides the XPath expression /manifest/@android:versionCode to extract the value of the android:versionCode attribute from the manifest.

Example output:

android:versionCode="1"

Use case 3: Display the AndroidManifest.xml of a specific module

Code:

bundletool dump manifest --bundle=path/to/bundle.aab --module=name

Motivation: Android Application Bundles can have multiple modules, each with its own AndroidManifest.xml file. This command allows developers to extract and view the manifest of a specific module.

Explanation:

  • bundletool dump manifest is the command to extract the AndroidManifest.xml file.
  • --bundle=path/to/bundle.aab specifies the path to the Android Application Bundle file.
  • --module=name specifies the name of the module for which the manifest needs to be extracted.

Example output:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.feature" android:versionCode="1" android:versionName="1.0">
    <application android:allowBackup="true" android:icon="@mipmap/module_icon" android:label="@string/module_name">
    ...
    </application>
</manifest>

Use case 4: Display all the resources in the application bundle

Code:

bundletool dump resources --bundle=path/to/bundle.aab

Motivation: Extracting all the resources from an Android Application Bundle can be useful for analyzing the resource usage, verifying resource compatibility, or extracting specific resources for further processing.

Explanation:

  • bundletool dump resources is the command to extract the resources from the bundle.
  • --bundle=path/to/bundle.aab specifies the path to the Android Application Bundle file.

Example output:

drawable/ic_launcher.png
layout/activity_main.xml
mipmap/ic_launcher.png
strings/app_name.xml

Use case 5: Display the configuration for a specific resource

Code:

bundletool dump resources --bundle=path/to/bundle.aab --resource=type/name

Motivation: Sometimes, developers need to know the specific configuration details of a resource in order to determine its compatibility or to troubleshoot resource-related issues. This command enables easy extraction of resource configurations.

Explanation:

  • bundletool dump resources is the command to extract the resources from the bundle.
  • --bundle=path/to/bundle.aab specifies the path to the Android Application Bundle file.
  • --resource=type/name specifies the type and name of the resource for which the configuration is needed.

Example output:

Configuration: ldpi
File: res/drawable-ldpi/ic_launcher.png

Use case 6: Display the configuration and values for a specific resource using the ID

Code:

bundletool dump resources --bundle=path/to/bundle.aab --resource=0x7f0e013a --values

Motivation: Extracting the configuration and values of a specific resource using its ID can be helpful when troubleshooting issues related to resource compatibility, resolution, or accessing resource values programmatically.

Explanation:

  • bundletool dump resources is the command to extract the resources from the bundle.
  • --bundle=path/to/bundle.aab specifies the path to the Android Application Bundle file.
  • --resource=0x7f0e013a specifies the resource ID for which the configuration and values are needed.
  • --values option displays the actual values of the resource.

Example output:

Configuration: ldpi
File: res/drawable-ldpi/ic_launcher.png
Values: @[res/drawable-ldpi/ic_launcher.png]

Use case 7: Display the contents of the bundle configuration file

Code:

bundletool dump config --bundle=path/to/bundle.aab

Motivation: The bundle configuration file contains metadata related to the Android Application Bundle, such as the application ID, split dimensions, compression settings, and more. Extracting and reviewing this information can be useful for debugging, verifying build settings, or analyzing bundle characteristics.

Explanation:

  • bundletool dump config is the command to extract the bundle configuration.
  • --bundle=path/to/bundle.aab specifies the path to the Android Application Bundle file.

Example output:

AppBundleConfig(bundleId=com.example.app, splitConfigs=[], compression={})

Conclusion:

The bundletool dump command provides various options to extract valuable information from Android Application Bundles. Developers can leverage this command to analyze bundle contents, troubleshoot resource-related issues, automate build processes, and perform data analysis.

Related Posts

How to use the command 'sails' (with examples)

How to use the command 'sails' (with examples)

Sails.js is a realtime enterprise level MVC framework built on top of Node.

Read More
How to use the command st (with examples)

How to use the command st (with examples)

st is a simple terminal emulator for the X Window System.

Read More
How to use the command nix-collect-garbage (with examples)

How to use the command nix-collect-garbage (with examples)

Nix-collect-garbage is a command in Nix that allows users to delete unused and unreachable nix store paths.

Read More