Hey everyone, I am once again back to discuss the latest changes in Harman AIR SDK (184.108.40.2063) and how to use them for Android. As you might have heard by now, this years big change for AIR devs will be the requirement to use Android App Bundle publishing format for all new apps and the bump of Target API level to 30 (Android 11). You can read all about all the changes in the official link.
We knew about this new format in a while now and knowing the benefits it brings, it is exciting to see that this is now available in the latest (Beta) version of AIR SDK from Harman. Although it was possible to compile .aab in earlier AIR versions, they weren’t recommended as they would crash in apps using ANEs or other Native resources.
Let’s dive in and see why this is important and how to build with the new format.
Why use AAB?
There is a simple answer on that..Well because it will be mandatory to do so after August 2021 for new apps, and in the well known pattern, same will apply for updates after November 2021. But this is more than a restriction. AAB actually come with many benefits, once of the most important ones being they save space for our users.
Android App Bundles offer the Dynamic Delivery of our apps, meaning that the user will only download chunks of the functionality they need. According to Google, many popular apps like LinkedIn shrank by about 23% and in some cases up to 50%.
How to use (IntelliJ)?
So how can we use this? Here I am going to present how to use this in IntelliJ cause this is what I use. If you are interested in other IDEs please leave a comment bellow and I will make sure to include a guide for that too.
Going through the Release notes, usage seems fairly straight forward simple apps. All you have to do, is use the adt tool with the new -target option aab.
adt -package -target aab <signing options> output.aab <app descriptor and files> [-extdir <folder>] -platformsdk <path_to_android_sdk>
So for example in one of my apps this is:
adt -package -target aab -storetype pkcs12 -storepass #### -keystore “android_dev_2048_2021.p12” “mk.aab” “Main-app.xml” “Main.swf” -platformsdk “I:\Development\android\sdk”
Although this works great for simple packaging, what happens if you want to do the same in IntelliJ cause you use 30 ANEs and a ton of resources? Here is what you have to do to prepare your environment*:
- Download the latest AIR SDK by Harman.
- Go to the adt configuration file (adt.cfg) which can be found in AIR_SDK_Folder/lib/adt.cfg.
- Add CreateAndroidAppBundle=true This will force your IDE to compile the aab.
- (Optional) Add KeepAndroidStudioOutput=true This will keep all the generated files under the bin-debug/AndroidStudio folder.
- *Specify the Android SDK folder (if you don’t have it already, you can download it here). This can be done either by using -platformsdk ‘Android_SDK_Folder’ in the Additional Compiler options or, if this doesn’t work like in my case, add it as an environment variable. To do so, navigate to Edit the system Environment Variables — Advanced- Environment Variables — New and add AIR_ANDROID_SDK_HOME as name and your path as value. Restart your IDE. / Alternatively you can add AndroidPlatformSDK=[android sdk folder] in adt.cfg
- Now open your project, make sure you select the appropriate AIR SDK and then go to Build — Package AIR Application as you would normally do. Once done you will have a new Android App Bundle in your deploy folder. In my case the file had a wrong extension (.apk) but was actually a .aab. Not sure if that is a bug or random, but if it happens to you, all you have to do is rename it.
And there you have it, AIR is now capable of building .aab which include all your ANEs without any issues (older AIR SDKs could compile to .aab but ANEs would make your app crash).
*Update 29/06/2021*: With the official release of version 533 (stable), you can skip step 5 and instead of creating an Environment Variable, you can set your Android SDK path in the adt.cfg using the AndroidPlatformSDK variable. The above guide should also work in Animate and Moonshine.
Are you ready to upload to Play store? Continue reading part 2: AIR / Apache Flex 2021: How to prep & upload Android App Bundle
Have questions about the process? Leave me a comment here.
FAQ (this will be updated as questions are coming in)
- “Multiple SDKs exist, choosing version 30.0.3 for packaging” message
This happens when you have multiple build-tools under your Android. AIR will auto-select the last one so don’t worry
*This works in 26/6/2021 but might change if Jetbrains integrates these options in the UI settings. If you want this to happen, please vote here.