Generate Apk file from aab file (android app bundle)
Is there any way to generate an apk file from android app Bundle via terminal or using android studio?
So far nobody has provided the solution to get the APK from an AAB.
This solution will generate a universal binary as an apk.
-
Add
--mode=universal
to yourbundletool
command (if you need a signed app, use the --ks parameters as required).bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks --mode=universal
MAIN STEP: Change the output file name from
.apks
to.zip
Unzip and explore
The file
universal.apk
is your app
This universal binary will likely be quite big but is a great solution for sending to the QA department or distributing the App anywhere other than the Google Play store.
By default, the IDE does not use app bundles to deploy your app to a local device for testing
Refer bundletool command
For Debug apk command,
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
For Release apk command,
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
--ks=/MyApp/keystore.jks
--ks-pass=file:/MyApp/keystore.pwd
--ks-key-alias=MyKeyAlias
--key-pass=file:/MyApp/key.pwd
Edit:
I have been using following commands while testing my release build for aab(I hope it helps others too):
-
Download
bundletool
jar file from Github Repository (Latest release > Assets > bundletool-all-version.jar file). Rename that file tobundletool.jar
-
Generate your aab file from Android Studio eg: myapp-release.aab
-
Run following command:
java -jar "path/to/bundletool.jar" build-apks --bundle=myapp-release.aab --output=myapp.apks --ks="/path/to/myapp-release.keystore" --ks-pass=pass:myapp-keystore-pass --ks-key-alias=myapp-alias --key-pass=pass:myapp-alias-pass
-
myapp.apks
file will be generated -
Make sure your device is connected to your machine
-
Now run following command to install it on your device:
java -jar "path/to/bundletool.jar" install-apks --apks=myapp.apks
Edit 2:
If you need to extract a single .apk
file from the .aab
file, you can add a extra param --mode=universal
to the bundletool
command:
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks \
--mode=universal \
--ks=/MyApp/keystore.jks \
--ks-pass=file:/MyApp/keystore.pwd \
--ks-key-alias=MyKeyAlias \
--key-pass=file:/MyApp/key.pwd
and execute
unzip -p /MyApp/my_app.apks universal.apk > /MyApp/my_app.apk
this will generate a single a /MyApp/my_app.apk
file that can be shared an installed by any device app installer
Ok here is the complete way I had to do:
-
Download
bundletool-all-0.10.3.jar
from this link, download the latest version available -
Create an app bundle using android studio and locate its path:
In my case its
E:\Projects\Android\Temp\app\build\outputs\bundle\debug\app.aab
-
Copy the bundletools jar to some location and get its path
In my case its E:\Temp\bundletool-all-0.6.0.jar
Use this command:
java -jar "BUNDLE_TOOL_JAR_PATH" build-apks --bundle="BUNDLE_PATH" --output=YOUR_OUTPUT_NAME.apks
In my case it will be
java -jar "E:\Temp\bundletool-all-0.6.0.jar" build-apks \
--bundle="E:\Projects\Android\Temp\app\build\outputs\bundle\debug\app.aab" \
--output=out_bundle_archive_set.apks
- This will create a file
out_bundle_archive_set.apks
, rename it to .zipout_bundle_archive_set.zip
, extract this file and done You will have multiple apk files
To install directly on external device use :
java -jar "E:\Temp\bundletool-all-0.6.0.jar" install-apks --apks=out_bundle_archive_set.apks
Check this blog post for more info . also check out official site
People have already explained on how to do this with the command-line. For completion, I thought I'd also show the way to do it via the UI in Android Studio.
When you open your "Run/Debug Configurations", you can select "APK from app bundle" (instead of "Default APK").
See screenshot: