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 upload new apps/updates in .aab format instead of the traditional .apk. The main objective of the Android App Bundle is to reduce the size of the app you download from the 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 the 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’s 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 in handy from a user point of view, but it added more headaches for developers and testers. Since it is not possible to install a .aab file like APKs, you need to either first upload it to the Play Store for testing or manually generate APK files from Android App Bundle (.aab). Once multiple APKs or universal APK files 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 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 by converting .aab file to APK and by installing it traditionally.
To extract APK files from Android App Bundle, we’re using bundletool, which is an open-source 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, download the latest version of bundletool jar file from GitHub and save it inside a folder on the Desktop. At the time of writing this article, the latest version of bundletool is 1.15.6 and for simplicity, change the file name from bundletool-all-0.15.6.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 bundletool
command.
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 device 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 named “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 standalone 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 the required APK from .aab file.
Here is a table with different bundletool flags and their usage.
Flag | Status | Explanation |
---|---|---|
–ks= | Optional | Keystore Path |
–ks-pass=pass: | Optional | Keystore password |
–ks-key-alias= | Optional | Key alias |
–key-pass=pass: | Optional | Key alias password |
–mode=universal | Optional | To generate a single Universal APK file |
–overwrite | Optional | Overwrites the output .apks file if the 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 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 a few more advanced flags like --device-spec
, --connected-device
, --device-id
to generate an APK and install the Android App Bundle on connected or specific device configurations. Apart from them you also have extract-apks
and get-size total
commands for more use cases. You can find more about them on the Android Developer Bundletool page here.
Conclusion for extracting APK files from AAB
To conclude, the one possible way to install the Android App Bundle (.AAB) is by uploading it directly to the Google Play Store for a set of testers or using 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.
Syam says
After renaming the .apks to .zip, I am unable to open the file as it says that “You do not have permission to open the document”. How to open the file now?
Syam says
Thank you for the detailed article. This article explains about how to generate signed .apk form .aab. But we need to upload signed .aab to playstore. Can you please let me know how to generate signed .aab?
Amar Ilindra says
You can generate the signed AAB from Android Studio. Go to Build – Generate Signed Bundle / APK… and choose Android App Bundle. Click Next.
Now select your Key store file and type Key store password, Key alias, and Key password. Now select Release and hit Finish.
Akshay Khandizod says
AAB to APK Converter
I have developed a windows tool for converting .aab files to .apk in Python.
It supports creating both debug and signed APK which can be directly installed to default android devices connected through USB.
It uses Google’s Bundle Tool in the backend.
Source Code: https://github.com/idzresearch/aab-to-apk-converter
This is the first tool that I have developed, Hope it is useful. I am open to suggestions and bug reports.
Amar Ilindra says
Great tool Akshay. It was a good start.
Consider improving the UI. Check Dribbble for inspiration.
George Birbilis says
Hi Akshay, does your tool generate universal APK?
Jeswin says
Rename the .aab file to .xapk and Install it using apkpure app…..
If it is not working, install the app directly from apkpure.
Download the app from apkpure.com
Any way it is not recommended to install apps from third party sources
majhi kalaji says
helps me a lot… thanks
humpty says
Kudos, This is saved me a lot of time!
btw,
(typo -ks=keystore.jks –ks=keystore.jks)
Amar Ilindra says
Glad you find the article helpful.
I couldn’t understand the typo you suggested. Can you please help me in finding the typo?
George Birbilis says
the typo is in the last combined command, it says “
-ks
” instead of “--ks
“Amar Ilindra says
Thanks, George Bribilis,
I fixed the typo.
santosh Kudalkar says
Very Nice Article, you explained very well. Only one thing I didn’t understand how you generated keystore.jks file in the folder. Can you please explain that.
Amar Ilindra says
keystore.jks
not generated. It is your original Keystore file. You need to either paste it manually into your folder OR provide the full file path.nath says
Hi Amar How to generate a keystorefile
Amar Ilindra says
You can generate the Keystore file from Android Studio. Select Build and then choose Generate Signed APK option. You will get a dialog to choose the existing Keystore along with a button to create a new Keystore file.
You just need to provide the basic details like organization name, address, alias, password, etc.
Note: Please make sure you remember the password or store it somewhere else. Resetting it later is a headache or may be impossible too.