How to target legacy versions of Adobe AIR runtime on Android using Flash Builder 4.7 (without using captive runtime)

The problem

Despite Adobe Flash falling out of favour for many web applications, Adobe AIR remains a great option for cross-platform mobile app development and rapid prototyping, and with the advent of captive runtime for Android it’s now possible to distribute apps without having to ask users to download and install the Adobe AIR runtime separately.

However, if you’re looking to distribute a simple experiment or throwaway game that’s just a few 10s of 100s of kilobytes on its own, wrapping it up with a near 10MB runtime isn’t quite as desirable.

So, you can just select “Export application that uses a shared AIR runtime”, right? Sadly not. If you’re targeting the original Kindle Fire (AIR 2.7), any of the Kindle Fire HD range (AIR 3.1), or the Nook HD or HD+ (AIR 3.3) you’ll find that they all come with embedded, non-updateable versions of the Adobe AIR runtime which are at least a few versions older than the AIR SDK used by Flash Builder 4.7 for ActionScript projects (this is how to update it, in case you wondered).

Assuming your app doesn’t use any of the features added in more recent versions of AIR, this is how you can target legacy runtimes using Flash Builder 4.7:

The solution

1. Edit the .actionScriptProperties file

While Flash Builder doesn’t have an option to change the compiler used for ActionScript or ActionScript Mobile Projects, you can switch your project from the new ASC2 compiler to the standard ActionScript Compiler (ASC) by editing your project’s .actionScriptProperties file:

  1. Use Explorer/Finder to navigate to your project folder and locate .actionScriptProperties
  2. Open the file in a text editor, and find/replace useFlashSDK=”true” with useFlashSDK=”false”
  3. Save .actionScriptProperties
  4. Close then open your project using the right-click menu options (or restart Flash Builder)

Now, if you open your project properties in Flash Builder (right click > Properties) and select ActionScript Compiler, you’ll see that you can select which version of the Flex SDK (which includes ASC), and therefore AIR SDK, you’d like to use to compile your project.

2. Add the required SDK(s)

If the SDK you need isn’t listed, Adobe has instructions for adding SDKs to Flash Builder here, and archived versions of both the Flex and AIR SDKs can be downloaded from:

3. Add -swf-version

Once you’ve edited .actionScriptProperties and installed your SDKs, the final step is to ensure that the your project uses the correct SWF version for the target AIR runtime.

To do this, open the ActionScript Compiler properties for your project and add -swf-version=XX on a new line in the “Additional compiler arguments:” text box, where XX is the appropriate number from this table.

4. That’s it!

Just debug and compile your project as before, and you’ll have a nice, tiny APK that works on even the most awkward of devices!

Using shared runtime with AIR SDK 3.7+

If you want to re-enable the ability to package Android apps without the captive runtime using AIR SDK 3.7+, set the AIR_ANDROID_SHARED_RUNTIME environment variable to true.

Device appears to be offline?

If you receive the an error saying “Device appears to be offline. Restarting the device may fix the problem.” while testing or debugging your app in Flash Builder, simply overwrite [legacy_sdk]\lib\android\bin with the same folder from the latest Adobe AIR SDK, or copy aapt.exe, adb.exe, AdbWinApi.dll, AdbWinUsbApi.dll and dx.jar (under lib rep) from [latest_android_sdk]\android-sdk\platform-tools into the folder, overwriting the files that are already in there.