Google PlayStore and automated deployment with AAB

Updating our deployment scripts to use Android App Bundles

Alistair Sykes
The Startup

--

AAB

The Android App Bundle was introduced at 2018’s Google I/O event. It’s the new official publishing format for Android apps. Google introduced it to reduce file sizes for users and introduce a few new features.

Coined Dynamic Delivery, Google will use an AAB to generate a more targeted APK file to delivery to the user. For example, they will only serve MDPI devices with MDPI resources.

Existing Scripts

Previously, I have discussed our automated deployment in this post. We use the Google Play Developer API via a bash script, to automate our deployment.

Updates

To now use AAB we had to make a couple of updates to our script.

Package name and version code

Previously our script used the APK to determine the package name and version code of the app. This meant our script could be used in different projects, without any extra configuration.

With AAB this is more difficult since we don’t have an APK to extract this information from. You could instead use environment variables to supply your script with this information. We decided to use the bundletool to get this information.

We use the bundletool to generate a universal (not device-specific) APK file. Then we extract the information the same way we before.

It’s worth noting the impact to build times, in comparison to environment variables. Is the generic deployment script worth the cost of a slightly extended build time?

Uploading AAB

The upload phase of the script had a few minor tweaks.

The HTTP request has a different Content-Type and Url but behaves the same as before.

All together

Here is our complete deployment build script:

Circle CI

We currently use CircleCi as our CI system. To call this script within a job:

We have to install the bundletool as it doesn’t come bundled in our docker image. We also need to make sure we have access to our keystore file, which we download using a URL to our private storage.

There are a couple of environment variables to be aware of:

COMMAND_CREATE_AABS_DIST_QAThis is the command used to create our AAB. We use an environment variable so that we don’t have to customise our config for different projects (with different flavour configurations). An example might be: ./gradlew bundleLiveApi ; AAB_PATH=$(find . -path “*/outputs/*Release*/*.aab” -print -quit) ;

PLAYSTORE_SERVICE_KEY — This is the service account key used to access the PlayStore.

Summary

Hopefully, this helps you to update your deployment process to make use of AAB and all its benefits.

References

https://developers.google.com/identity/protocols/OAuth2ServiceAccount#authorizingrequests — The HTTP/REST tab

https://developers.google.com/identity/protocols/OAuth2ServiceAccount#callinganapi https://developers.google.com/android-publisher/api-ref/edits/bundles/upload

Also checkout

Previous Post

Originally published at https://www.brightec.co.uk.

--

--