Having already optimized my game Word Up Dog so that it runs relatively well in a browser on an Android phone, I was ready to package it up as an installable app. Adobe Air makes this easy to do with few changes to your original code. Adobe has a Flash CS5 plugin to do it, but I prefer to do things the free-and-open way when I can, so here’s how I built the Android app using only FlashDevelop and other free Windows tools.
First, I don’t recommend the Android emulator. I struggled with getting emulator-compatible versions of the Air packager and Air runtimes installed. There didn’t seem to be much advantage so use a phone if you can get your hands on one.
- Download the Air 2.5 SDK, paste it into a copy of your Flex SDK directory, and set FlashDevelop to compile using the result
- Start a new FlashDevelop AIR AS3 project
- AddChild your existing game in Main.as
- Add NativeApplication handlers to prevent the phone from idling
- Add android-specific settings to application.xml (here, have mine)
- Generate a certificate using
adt -certificate -cn WordUpDog 1024-RSA certificate.pfx yourpass
- Build your air project to create WordUpDog.swf
- Package the swf into an apk file with
adt -package -target apk -storetype pkcs12 -keystore certificate.pfx -storepass yourpass WordUpDog.apk application.xml -C . WordUpDog.swf iconsFolder
- Upload WordUpDog.apk to your phone and baby, you’ve got a stew going
I was prompted to install the Air interpreter the first time I ran the game on my Nexus One, then it behaved just like any other app. The performance was about the same as running the SWF through the phone’s browser, but of course there are advantages to being installed. I could force the game to stay in landscape perspective and add a customized handler to deal with incoming phone calls. Not to mention being able to upload and sell it on the Android app store!
Next I’ll tackle Air on the iPhone.