How to publish Android appBundle to Google Play Store

App Bundle is a new way to package an Android app. It modularizes your app by architecture behind the scenes making your APK size smaller. Packaging feature available only in Android Studio 3.2.+. Developers uploads a new package myappbundle.aab to play store, the user downloads App and the device will automatically download the app for its architecture. Previously the developer had two generate and upload apks for each architecture. For example, if your app split architectures you had to generate APKS for armv7a, x86 and fat, and now with the app bundle you only generate and publish one file myappbundle.aab.

First, we need to modify our build.gradle to support bundles. Add below code:

bundle {
language {
enableSplit = true
}
density {
enableSplit = true
}
abi {
enableSplit = true
}
}

Then we need to register with Google Play App Signing. From the developer app console go to “App signing tap” follow instructions. Use below command to generate the key you need to upload to Google Play Store. New app sign process:

andres@andress-mbp:~$ java -jar /Users/andres/Downloads/pepk.jar --keystore=/Users/andres/Documents/1_certs_Master_Apps/Android_Apps1/BornIn-key/BornIn-android-key --alias=BornIn-android-key --output=/Users/andres/Documents/1_certs_Master_Apps/Android_Apps1/BornIn-ke/ --encryptionkey=eb10fe8f7c7c9df715022017b00c6471f8ba8170b13049a11e6c09ffe3056a104a3bbe4ac5a955f4ba4fe93fc8cef27558a3eb9d2a529a2092761fb833b656cd48b9de6aEnter store password:Enter key password:andres@andress-mbp:~$

Then upload the app blundle file *.aab to play store same process as *.apk.

2. Upload new App package (bundle.aab) to Play Store. To generate a release app bundle run below gradle command. The new command generates a file “bundle.aab” instead of many *.apk files. New app bundle package is located in: /../app/buld/outputs/bundle/release/bundle.aab

./gradlew bundleRelease

How to use bundletool to decompile appBundle(*.aab) and get APK:

It‘s a really good solution to reduce your app size and publishing, but what about testing? Currently, our CI/CD flow puts the different architecture apks into S3 buckets, ex: Daily build and Release builds. But now that we generate only one package how is your Test Automation(firebase TestLab) or QA going to get the apk’s to test on? To solve this issue Google created the tool “bundletool” it’s a script that will generate apks for a specific architecture from the app bundle package “myAppBundle.aab”. Below commands show how to create apks from “myAppBundle.aab”. The only downside is to generate APK’s from CI :(

  1. Download tool”bundletool.jar” to decompile file *.aab into apks file. Generates all architecture apks (800MB)
$java -jar bundletool-all-0.6.2.jar --output/MyApp/my_app.aab --output=/MyApp/my_app.apks

2. Command to generate universal Release APK for all devices.

$bundletool build-apks --bundle=myapp_bundle.aab --output=myapp.apks --universal

For Release build you need to add keystore and sign passwords.

$java -jar bundletool-all-0.6.2.jar build-apks --bundle=/Users/asandoval/dev/android/TuneIn/tunein/build/outputs/bundle/googleFlavorTuneinFreeRelease/tunein.aab --output=/Users/asandoval/dev/android/TuneIn/tunein/build/outputs/bundle/googleFlavorTuneinFreeRelease/TuneInApp.apks --universal --ks=/Users/appsign.keystore --ks-pass=pass:password --ks-key-alias=appalias —-key-pass=pass:password

The above command generates a file *.apks, to get the universal apk we need to unzip the file with command:

$unzip out.apks -d apks

2. Install APK on emulator/device from *.apks use below command:

$ java -jar bundletool-all-0.6.2.jar install-apks --apks=/Users/asandoval/dev/android/TuneIn/tunein/build/outputs/bundle/googleFlavorTuneinFreeRelease/tunein.apks

WIP: Solution to fix broken CI/CD flow: Add bundletool.jar to our docker image, and a script to get universal APK from *.aab, then push generated APK to s3 bucket.

Notes:

Android developer notes, background, beta

Google io18 talk below:

$bundletool build-apks --bundle=myapp_bundle.aab --output=myapp.apks --universal

software engineer, read, swim, travel. apps: https://goo.gl/rDuuQw https://goo.gl/15GvfE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store