N Kaushik

How to export apks from Android app bundle

July 10, 2021

How to export apks from Android app bundle:

Bundling is the new way to distribute Android applications on PlayStore. Instead of creating one or multiple apks and uploading them to the PlayStore, we can create one bundle file and upload it instead. PlayStore will create different apks for different devices automatically.

Bundling is a better way to ship Android apps because it creates different optimized APKs for different devices.

If you have used split-apks to create multiple apks, bundling is just an optimized way to do that.

In this post, I will give an overview of Android app bundling and how to extract the APKs from a bundle for testing.

What is a bundle file in Android:

Bundle files are .aab files. These are similar to apk files, i.e. they includes compiled code and resources, but unlike an apk, we can’t install .aab file in a phone directly.

For testing a release build, creating apk is the recommended way.

Bundling using gradle:

Gradle task bundleVariant is used to create a bundle. For example:

./gradlew bundleDebug

It will create one debug bundle file. Similarly, we can create one bundle for release using the below command:

./gradlew bundleRelease

If your signing configuration is written in the build.gradle, it will create one .aab file that we can upload directly to the PlayStore.

If your signing configuration is not in the build.gradle file, you need to use jarsigner to sign it:

jarsigner -keystore {keystore-path} {.aab-path} {key-alias}

You can replace the variables with their actual values and it will create the final signed bundle, that can be uploaded to PlayStore.

Bundling using Android Studio:

Creating a bundle in Android studio is similar to building apks.

Click on Build -> Generate signed bundle or APK, it will open one window.

Android app bundle Android Studio

Select Android App Bundle, click on Next, it will ask you to enter keystore information similar to building apks. Enter these info and it will create the final .aab file.

This is signed, so we can upload it on PlayStore.

How to get the apks from App bundle:

Once a bundle is created, we need to upload it to PlayStore and playstore creates different apks for different devices. We can download one apk from PlayStore to test it on a device, but that is not an optimal solution.

There is a command-line tool called bundletool that can be used to decompile a .aab file to apks.

  • First of all, download it from Github here
  • Now, use the below command to build all apks:
bundletool build-apks --bundle=/path/app.aab --output=/path/app.apks

This command will work only for debug bundles. For release bundles, use the below command:

bundletool build-apks --bundle=/path/app.aab --output=/path/app.apks

You can also use the below command to generate apks only for the connected devices:

bundletool build-apks --connected-device.......

Installing the apks:

We can install all generated apks using bundletool. The below command installs the apk from the generated apks:

bundletool install-apks --apks=/path/app.apks

This way, we can easily test out apks before uploading the bundle on playstore.

Subscribe to my Newsletter