In Google, I/O 2018, Android App Bundle, a new file format was introduced to distribute Android apps via Google Play. Later in 2019, Google started recommending developers to upload new apps/updates in .aab format instead of traditional .apk. The main objective of Android App Bundle is reducing the size of the app you download from Play Store. Technically it is a collection of different APKs generated dynamically for various device configurations. If you want to install .aab file outside of Play Store, you need to first extract APK files from AAB and install them manually on your Android device.
Unlike traditional .apk files, it is not possible to share or sideload the .aab file for testing. When you upload the .aab file in your Google Play Console, an optimized .apk file will be dynamically generated based on the user device configuration.
For example, if an Android app has multiple “strings.xml” files for different languages and your device default language is set to English. A .apk file will be generated dynamically for your device excluding all other language files to reduce the .apk size.
This feature comes handly from a user point of view but for developers and testers, it added more headache. Since it is not possible to install a .aab file like APKs, you need to either first upload it to Play Store for testing or manually generate APK files from Android App Bundle (.aab). Once multiple APKs or universal APK file is extracted from .aab, you can install the app on different device configurations.
Converting Android App Bundle (.aab) to APK File
After generating the Android App Bundle from Android Studio or from your favorite IDE, you need to first test how the generated APKs behave when deployed on local mobiles. The quickest way to do this is converting .aab file to APK and by installing it in the traditional way.
To extract APK files from Android App Bundle, we’re using bundletool, which is an opensource command-line tool available on GitHub. This tool is for manipulating the Android App Bundle to generate APK set archive (.apks) file. Once the “.apks” file is generated using bundletool, we can extract the APK files by changing the file to .zip format.
Here is how you can use bundletool to generate .apks archive file from Android App Bundle and extract .apk files:
Step 1: Download bundletool command-line tool
First things first, download the latest version of bundletool jar file from GitHub and save it inside a folder on Desktop. At the time of writing this article, the latest version of bundletool is 0.10.2 and for simplicity, change the file name from bundletool-all-0.10.2.jar to bundletool.jar
Step 2: Generate APK Set Archive (.apks) file from .aab
Copy your Android App Bundle (.aab) file to the same folder where you have downloaded the bundletool.jar in previous steps. This is very important and you must make sure both bundletool.jar and .aab file is in the same folder every time you run the
As shown in the screenshot, the name of my Android App Bundle is nhl.aab and both “bundletool.jar” and “nhl.aab” files are in the same folder. For this tutorial, we are using the AAB file of our Notification History application.
Now open the Command Prompt (Windows) or Terminal (Mac) and change the directory to your Desktop folder using the
CD command. To generate an APK set archive (.apks) file containing different APK files of all devices configurations your app supports, run the
build-apks command as shown below.
java -jar bundletool.jar build-apks --bundle=nhl.aab --output=nhl.apks
- bundletool.jar – The name of .jar file you downloaded from GitHub
- nhl.aab – Your Android App Bundle file name
- nhl.apks – The name of the output file. It is a .apks file. Don’t confuse it with the traditional .apk file.
After running the above command, a new file with the name “nhl.apks” will be created in the same folder. This is an APK archive file and by extracting it, you will get multiple APK files for different device configurations.
Step 3: Extract APK Files
Once the “nhl.apks” file is generated, it is very easy to extract APK files from it. All you have to do is, rename the “nhl.apks” file to “nhl.zip” and extract it normally using ZIP file extractor. You will now find a lot of APK files in splits and standalones folders.
Now you have successfully converted the .aab file to .apk files and you can install them on your device normally. Technically, this is how you can install .aab file on an Android device.
Wait it’s not over yet. Did you notice any problem with the above command? Yes, it is generating plenty of Debug APK files and you are not sure about which one you need to install? What if you want signed APKs or a universal signed APK from Android App Bundle. Fortunately, bundletool comes with different flags for extracting required APK from .aab file.
Here is a table with different bundletool flags and its usage.
Key alias password
|–mode=universal||Optional||To generate a single Universal APK file|
|–overwrite||Optional||Overwrites the output .apks file if same file name exists|
Let’s take a look at how to use these flags along with bundletool command.
Generating Signed APKs using your Keystore
To generate signed APK files with your own keystore file, run the below command.
java -jar bundletool.jar build-apks --bundle=nhl.aab --output=nhl.apks --ks=keystore.jks --ks-pass=pass:your_keystore_password --ks-key-alias=your_key_alias --key-pass=pass:your_key_password
This will again generate an “nhl.apks” file and you need to rename it to “nhl.zip” and extract the zip file to see signed apks in both splits and standalone folders.
Generating a Universal APK from Android App Bundle
If you want to generate only one single APK from your .aab file, run the below command.
java -jar bundletool.jar build-apks --bundle=nhl.aab --output=nhl.apks --mode=universal
This command will generate nhl.apks file and again you need to rename it to nhl.zip and extract it to get universnal.apk file.
Overwriting existing .apks file
If you want to overwrite the old .apks file with the new one, you need to just add the –overwrite flag to your command as shown below.
java -jar bundletool.jar build-apks --bundle=nhl.aab --output=nhl.apks --overwrite
Extracting Signed Universal APK file from Android App Bundle
Now let’s combine all the above flags to generate a single universal APK file and also overwrite the existing APK archive if already available.
java -jar bundletool.jar build-apks --bundle=nhl.aab --output=nhl.apks --overwrite --mode=universal -ks=keystore.jks --ks-pass=pass:your_keystore_password --ks-key-alias=your_key_alias --key-pass=pass:your_key_password
After running this command, you will need to rename the generated “nhl.apks” file to “nhl.zip” and extract it to find the signed “universal.apk” file.
There are few more advanced flags like
--device-id to generate APK and install Android App Bundle on connected or specific device configurations. Apart from them you also have
get-size total commands for more use-cases. You can find more about them at Android Developer Bundletool page here.
Conclusion for extracting APK files from AAB
To conclude, the one possible way to install Android App Bundle (.AAB) is uploading it directly on Google Play Store for a set of testers or use the
bundletool command to convert .aab to .apk file. If your app is big and has a lot of active users, use the bundletool to test the app on different device configurations and roll out the updates slowly. However, if your app is new, you can prefer adding the App Bundle in closed alpha to gather the feedback.
In the long run, it is always better to extract APKs from the App Bundle first. And test them manually on local devices before submitting the update from your Google Play Console.