DevOps for Android App Bundles

James Montemagno

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.  

Shrink Android App Size 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:

 

 

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.

App Center

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!  

Build App Bundle in App Center
  When the build has finished, easily download your files or submit them directly to Google Play for distribution.
Download App Bundle App Center
  Learn more about how App Bundle support in App Center on their blog.  

Azure DevOps

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.  

Azure DevOps download keystore
  If you are already building your app in Azure DevOps, simply clone your existing “Build Android App” step. Otherwise, add a new Xamarin.Android build task. Here you will specify your Project Path, Output Directory, and Build Configuration. You will need to continue checking the Create app package option. The main difference being that you will want to pass in Additional arguments for the build to package and sign the App Bundle:


-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!  

Packages from Azure DevOps
 

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.  

  For deeper dive topics, be sure to read the previous blog on Shrinking your Android App Size. Additionally, follow along with all our documentation on preparing your Android app for release.

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • Stuart Lang 0

    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.

  • Michael Stancombe 0

    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

    -p:AndroidSigningKeyAlias="$(KeystoreAlias)"

    results in the detailed output when the alias has a space in it (eg, ‘Test Keystore Alias’)

    C:\Program Files\Android\Jdk\microsoft_dist_openjdk_1.8.0.25\bin\jarsigner.exe -keystore C:\agent2_work_temp\test.keystore -storepass "" -keypass "" -digestalg SHA-256 -sigalg SHA256withRSA -signedjar C:\agent2_work\33\b/Release\com.testthing-Signed.aab C:\agent2_work\33\s\Test.MobileApp\Test.MobileApp.Android\obj\Release\90\android\bin\com.testthing.aab Test Keystore Alias  (TaskId:390)
    Only one alias can be specified (TaskId:390)
    Please type jarsigner -help for usage (TaskId:390)
    [error] ... Xamarin.Android.Common.targets(2853,2): Error MSB6006: "jarsigner.exe" exited with code 1.

    My workaround was pretty simple: don’t use a space in the alias.

Feedback usabilla icon