bundletool

    bundletool is the underlying tool that Gradle, Android Studio, and GooglePlay use to build an Android App Bundle or convert an app bundle into thevarious APKs that are deployed to devices. bundletool is also available toyou as a command line tool, so you can recreate, inspect, and verify GooglePlay’s server-side build of your app’s APKs.

    You should use Android Studio and the Android plugin for Gradle to.However, if using the IDE is not an option (for example, because you’re using a continuousbuild server), you can alsobuild your app bundle from the command lineand sign it using.

    Note: You can not use apksigner to sign your app bundle.

    By default, the IDE does not use app bundles to deploy your app to a localdevice for testing. However, you canmodify your run/debug configurationand select the option to deploy APK from app bundle to see how it affectsyour app's execution.

    If you haven't already done so, download bundletool from the.

    When bundletool generates APKs from your app bundle, it includes them in acontainer called an APK set archive, which uses the .apks fileextension. To generate an APK set for all device configurations your appsupports from your app bundle, use the bundletool build-apks command, asshown below.

    1. bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
    2. --ks=/MyApp/keystore.jks
    3. --ks-pass=file:/MyApp/keystore.pwd
    4. --ks-key-alias=MyKeyAlias
    5. --key-pass=file:/MyApp/key.pwd

    The table below describes the various flags and options you can set when usingthe bundletool build-apks command in greater detail. Only—bundle and —output are required—all other flags are optional.

    After you generate a set of APKs, bundletool can deploy the rightcombination of APKs from that set to a connected device.

    For example, if you have a connected device running Android 5.0 (API level 21)or higher, bundletool pushes the base APK, dynamic feature APKs, andconfiguration APKs required to run your app on that device. Alternatively, ifyour connected device is running Android 4.4 (API level 20) or lower,bundletool looks for a compatible multi-APK and deploys it to your device.

    To deploy your app from an APK set, use the install-apks command and specifythe path of the APK set using the—apks=/path/to/apks flag, asshown below. (If you have multiple devices connected, specify a target deviceby adding the flag.)

      If you’d rather not build a set of APKs for all device configurations your appsupports, you can build APKs that target only the configuration of a connecteddevice using the —connected-device option, as shown below. (If you havemultiple devices connected, specify a target device by including the—device-id=serial-id flag.)

      bundletool is capable of generating an APK set that targets a deviceconfiguration specified by a JSON file. To first generate a JSON file for aconnected device, run the following command:

      1. bundletool get-device-spec --output=/tmp/device-spec.json
      1. bundletool build-apks --device-spec=/MyApp/pixel2.json
      2. --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks

      If you don’t have access to the device for which you want to build a targetedAPK set (for example, a friend wants to try your app with a device you don’thave on-hand), you can manually create a JSON file using the following format:

      You can then pass this JSON to the bundle extract-apks command, as describedin the previous section.

      If you have an existing APK set and you want to extract from it a subset of APKsthat target a specific device configuration, you can use the extract-apkscommand and specify a device specification JSON, as follows:

      1. bundletool extract-apks
      2. --apks=/MyApp/my_existing_APK_set.apks
      3. --output-dir=/MyApp/my_pixel2_APK_set.apks
      4. --device-spec=/MyApp/bundletool/pixel2.json

      To measure the estimated download sizes of APKs in an APK set as they wouldbe served compressed over-the-wire, use the get-size total command:

        You can modify the behavior of the get-size total command using thefollowing flags:

        FlagDescription
        —apks=path(Required) Specifies the path to the existing APK set file whose download size is measured.
        —device-spec=pathSpecifies the path to the device spec file (from get-device-spec or constructed manually) to use for matching. You can specify a partial path to evaluate a set of configurations.
        —dimensions=dimensionsSpecifies the dimensions used when computing the size estimates. Accepts a comma-separated list of: SDK, ABI, SCREEN_DENSITY, and LANGUAGE. To measure across all dimensions, specify ALL.
        —instantMeasures the download size of the instant-enabled APKs instead of the installable APKs. By default, bundletool measures the installable APK download sizes.
        —modules=modulesSpecifies a comma-separated list of modules in the APK set to consider in the measurement. The bundletool command automatically includes any dependent modules for the specified set. By default, the command measures the download size of all modules installed during the first download.

        To learn more about using bundletool, try the following resource.

        • Your First Android App Bundle,a codelab that explores the basic principles of Android App Bundles and showsyou how to quickly get started with building your own using Android Studio.This codelab also explores how to test your app bundles.