DevOps for Android App Bundles
Android App Bundle is a new app packaging format from Google for Android applications that dramatically reduces the install size for end users. Traditionally, when building an Android app, one would create one large APK file that all users would receive. When packaging your app in an App Bundle, applications are delivered dynamically to users based on their specific device. This means, the app that is installed is reduced in size by up to 50% with absolutely no code changes! We introduced support last year in Visual Studio 2019 16.3 and Visual Studio for Mac 2019 8.3 to package apps with App Bundles.
Truly Smaller Apps
When using the App Bundle format users get only the languages, resources, and architecture for their specific device. This work is done by Google Play and it really reduces your app size based on your compilation settings. Our developers are seeing amazing success using App Bundle. Here is a tweet from our very own Brandon Minnick, who recently updated his app to use App Bundles:
🎉 I just published an update for my Android app using Android App Bundles
🤯 As promised, it reduced the app download size from 96.5MB to 29.8MB#XamarinForms #XamarinAndroidhttps://t.co/ORCqPJGV0r
— Brandon Minnick @ Update Prague 🇨🇿 (@TheCodeTraveler) October 15, 2019
To learn more about how App Bundle works and how to setup your project, read through the previous post on App Bundle support from Jon Douglas. He shows you how to enable App Bundle in your Android app and how to produce a local archive directly from Visual Studio 2019 and Visual Studio for Mac 2019.
You might be generating your builds with continuous integration with App Center or Azure DevOps. So today, I want to walk you through how to setup and use App Bundles in your DevOps pipeline.
In September, App Center released official support that automatically detects your project settings. However, if you don’t want to change your project settings or want full control, you can easily adjust build settings to create an APK and AAB file when you build!
If you are building your Android application in Azure DevOps, it takes just a few steps to package your application into an App Bundle. For testing purposes it is recommended to continue building an APK, in addition to an AAB for app store distribution.
The first step is to ensure you have your Keystore available to sign your App Bundle. This can be done by Downloading Secure File task and uploading your Keystore. Additionally, specify a reference name under Output Variables. This will allow you to reference it in the next step through a variable.
-restore -t:SignAndroidPackage -p:AndroidPackageFormat=aab -p:AndroidKeyStore=True -p:AndroidSigningKeyStore=$(keystore.secureFilePath) -p:AndroidSigningStorePass=$(KeystorePassword) -p:AndroidSigningKeyAlias=$(KeystoreAlias) -p:AndroidSigningKeyPass=$(KeystorePassword)
Here are the specified Keystore passwords and alias in the Variables section of the build pipeline. As well as the Keystore patch from the name specified earlier. Now, when you build your app, you will have both an APK and an AAB file ready to distribute!
Optimize and Shrink Your App
For a full breakdown of what App Bundles are and how they work, checkout the full Xamarin Show with Jon Douglas.
Great stuff! I’d love to be able to distribute AAB bundle via AppCenter too, I’m currently building a APK from Azure DevOps, when I switched to AAB I only found out there was an issue (due to a 3rd party) with using AAB in our Play Store Closed Track, so AppCenter is letting us down here.
Thanks, was very useful 🙂
I did hit a snag worth mentioning: If there is a space in the keystore alias the build will fail. Turning on verbose logging seems to show that msbuild is not quoting the alias when calling jarsigner, regardless of whether it is passed in quoted, eg, using
results in the detailed output when the alias has a space in it (eg, ‘Test Keystore Alias’)
My workaround was pretty simple: don’t use a space in the alias.