To start with – what is Android App Bundle (AAB)? According to Google, the Android App Bundle is Android’s new, official publishing format that offers a more efficient way to build and release your app. The Android App Bundle lets you more easily deliver a great experience in a smaller app size, which can improve install success and reduce uninstalls. You don’t need to refactor your code to start benefiting from a smaller app. And once you’ve switched, you’ll benefit from modular app development and customizable feature delivery. (for more check https://developer.android.com/platform/technology/app-bundle).
To summarize and to compare with older APK approach. APK is one-package-for-all-devices deployment approach. It contains all information, binaries and other artifacts for all supported Android devices – in one package. All Android devices get the same APK and use only artifacts for target device. For example: if you are targeting hdpi and xhdpi resolution devices both will get all graphical content, but will use only those images and other graphical items related to target resolution. On the other hand, AAB format and deployment mechanism slice down deployment package to parts and deploy only artifacts needed for that device. Similar is with language resources and processor-specific binaries: e.g. armeabi-v7a based Android devices will not get arm64-v8a compiled binaries, an vice versa. This way, only minimum required package is deployed to target Android device. Thus, reducing size and increase overall installation experience.
For Xamarin developers, this feature is very new. Support in Visual studio was introduced in December 2019 in Visual Studio 2019 16.3. Check release notes here https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes#android-app-bundle for more information.
In this blog post I will show how I extended my existing Azure DevOps build pipeline with Android AAB package creation.
Android App Bundle with Azure DevOps build pipeline
At first, when I extended my msbuild task I got some strange errors! Then It hit me, this feature is totally new on the scene, so first I need to update my build agent to the latest version. I did this by setting Agent pool in my build pipeline from Hosted VS2017
to AzurePipeline/windows-2019
where all latest features exist.
I changed my build pipeline Agent pool from…
to….
In my build process I am using msbuild task to create Android packages. I will reuse this practice also for creating AAB. It’s also very important to set msbuild version to the latest version.
Creating AAB is basically very simple, all I need is changing msbuild property AndroidPackageFormat from apk to aab. That’s it, simple right? See picture below to see it in action.
For consistency and for the record: these are my msbuild arguments for creating APK:
1 2 3 4 5 6 7 |
/t:SignAndroidPackage /p:AndroidKeyStore=true /p:AndroidSigningKeyAlias=$(JenxSigningKeyAlias) /p:AndroidSigningKeyPass=$(JenxKeyStorePass) /p:AndroidSigningKeyStore="$(Build.SourcesDirectory)/build/cert/Jenx.keystore" /p:AndroidSigningStorePass=$(JenxKeyStorePass) /p:AndroidPackageFormat=apk |
and this is for AAB:
1 2 3 4 5 6 7 8 |
/t:SignAndroidPackage /p:AndroidKeyStore=true /p:AndroidSigningKeyAlias=$(JenxSigningKeyAlias) /p:AndroidSigningKeyPass=$(JenxKeyStorePass) /p:AndroidSigningKeyStore="$(Build.SourcesDirectory)/build/cert/Jenx.keystore" /p:AndroidSigningStorePass=$(JenxKeyStorePass) /p:AndroidPackageFormat=aab /p:AndroidUseAapt2=true |
When I run my pipeline, my publishing tasks put my APK and AAB in my Azure DevOps Artifacts repository.
Even raw file size comparison shows that my AAB is drastically smaller then my APK. Now that I have Android App Bundle I can deploy it to Google Play and use all the benefits of AAB format.
Conclusion
Android App Bundle is the latest, preferred way of deploying Android applications.
In this blog post I presented how to create Android App Bundle with Azure DevOps pipelines.
While AAB introduces a lot of benefits, it also brings some complexities into development process. For example, you can not just deploy AAB file to testing device and start the application as with APK.
In one of the next blog post I will present how you can start testing AAB on your device by “extracting” device specific APK from AAB.
Until then, happy coding.
2 thoughts on “Xamarin.Forms: Create Android App Bundles with Azure DevOps”
Thanks, for writing this guide, it’s been very helpful.
However, I’ve followed everything, but when I try to upload the aab bundle to the Play Store it says “The Android App Bundle was not signed.”. Do you have any idea why that might be?