Convert an Android Application Bundle (.aab) to an Android Package (.apk)?

What is an Android Application Bundle?

Sometimes a developer gives you an .aab file instead of an .apk however your MDM only accepts an .apk for upload.

What is this .aab format?

An Android App Bundle is a publishing format that includes all your app’s compiled code and resources, and defers APK generation and signing to Google Play. Google Play uses your app bundle to generate and serve optimized APKs for each device configuration, so only the code and resources that are needed for a specific device are downloaded to run your app. You no longer have to build, sign, and manage multiple APKs to optimize support for different devices, and users get smaller, more-optimized downloads.

source

How do you generate an apk from the aab you got? A high level overview.

Download bundletool

Google has created the bundletool to manipulate Android App Bundles. This tool can also generate an APK from App Bundles.

You can find the latest release on Github. Download the jar file and rename it to bundletool.jar.

The bundletool requires a working java runtime on your computer. You will also need to have a signing key available to sign the apk.

Run bundletool

You run the tool from the command line. Below is an example on how to generate an universal apk from the aab file.

java -jar bundletool.jar build-apks --mode=universal --bundle=input.aab --output=output.apks \
--ks=keystore.jks \
--ks-pass=file:keystore.pwd \
--ks-key-alias=MyKeyAlias \
--key-pass=file:key.pwd

More details on the parameters of bundletool can be found here.

Don’t forget to set the mode to universal so that bundletool builds only a single APK. This APK includes all of the app’s code and resources creating an APK compatible with all device configurations the app supports.

Extract the apk

After running bundletool you will have an .apks file. Rename the extension from .apks to .zip and extract universal.apk from that zip. You can import the universal.apk into your MDM.

As a side note I want to mention you can also ask your vendor / developer to generate an .apk for distribution through an MDM when building the app. That might save you some time fiddling around with tools.