Pre-Hero Flex AIR for Android Workflows with Flash Builder 4

Posted on September 25, 2010 | Comments Off

Until the next preview releases of Flash Builder “Burrito” come out the mobile workflow in Flash Builder has yet to be defined. By the way a great place to come learn about the latest “Burrito”, “Hero”, and “Panini” information is at MAX in Los Angelos next month.

In this post I’ll walk through one possible workflows for using Flash Builder 4 to build AIR for Android applications. This are not meant to be the perfect workflow but really to show how to get up and running the current state of things. Flash Builder 4 supports various project types and I’ll talk about a couple ways to go about using them. I will you know how to get the latest AIR for Android SDK from the prerelease and have it setup in your Flash Builder 4 SDK list.

Flex Project – Desktop (runs in Adobe AIR) Workflow
First thing is to create your project. In Flash Builder 4, Select File -> New -> Flex Project. Now you will check the “Desktop” check box, select proper SDK (that has AIR for Android SDK overlayed on it), and give the project a name. See the screen shot below:

The next steps are allow you to build for Android but still run the code in adl through Flash Builder 4 on your desktop. The following steps uses the project “AIRForAndroidDesktop”, AIRForAndroidDesktop.mxml, AIRForAndroidDesktop-app.xml

  • Change your main application from s:WindowedApplication to s:Application
  • Open the AIRForAndroidDesktop-app.xml and set:
    • <systemChrome>standard</systemChrome>
    • <visible>true</visible>
  • Open up Project Properties -> Flex Build Path -> Library Path. Set “Framework Linkage:” to “Merged into code”

Now put a button into the main application so something is there. At this point you can run the application on your desktop to test non-device specific code (good idea to use the new Capabilities class and isSupported properties on major features). Since Flash Builder 4 doesn’t have hooks to the adt for packaging the AIR applicaiton to an .apk yet you will have to do that step in the command line or with ANT.

To package up your apk with this project’s setup there is a copy things to be aware of. First for development and testing the easiest approach is to create a script that calls adt on the swf that is generated in the bin-debug folder. You can find this “package.sh” shell script in the project source files and its run by running the command below in Terminal in the root of the Project folder:

promtp$./package.sh AIRForAndroidDestkop

Here is what the shell script source:

# ARGUMENTS
appname=$1

# PATHS - CHANGE TO YOUR NEEDS
USER_WORKSPACE=/Users/renaun/Documents/workspaces
SDK_PATH=$USER_WORKSPACE/FlexSDKs/flex_sdk_4.1.0.16076_air25
ANDROID_PATH=$USER_WORKSPACE/Devices/android/android-sdk-mac_86/tools

# MOVE INTO BIN-DEBUG
cd bin-debug
#PACKAGE
$SDK_PATH/bin/adt -package -target apk -storetype pkcs12 -keystore $USER_WORKSPACE/air_cert.p12 -storepass your_password $appname $appname-app.xml $appname.swf

# PUSH ONTO DEVICE
$ANDROID_PATH/adb install -r $appname.apk

Now that’s the very basics of getting the project to compile right and get on to the Android device. Once you really want to put it on the device you’ll want to build the application properly (non-debug) and a great short term way, until Burrito comes out, to do this is use Jon Campos’s ANT scripts or Jesse Freeman’s AntPile.

There are a bunch of options inside the application descriptor file for going fullscreen to setting android permissions. You can tweak those attributes app.xml all you want.

Creating AS only apps or Flex Project -> Web type projects work similarly in the sense that you find where it creates the SWF and then use adt to package up for Android. Again all this will change with the latest release of Hero and Burrito. Come to MAX to see more progress in this area.