How to build your first AIR4Android application using FDT and Eclipse

If you own an Android 2.2 (Froyo) device you must know that you can already start building (and testing!) your AIR 2.5 applications for Android. There’s more: if you are an FDT user like me you should be glad to know that is very easy to build and package our AIR4Android applications without even leaving our favorite tool!

Let’s start

I’m not going deep into how to setup your Eclipse environment with FDT as I assume you already have some sort of confidence with both of them. Let’s say you have a working copy of Eclipse and just installed FDT professional (or whatever version you like). Once you have these programs installed we can take care of SDKs.

SDKs

Go to Android developer portal and download & install latest Android SDK for your platform. You can simply follow default installation instructions for this. In the same way download Flex 4.1 SDK and extract all content in a specific folder of your hard disk. At this point you just need to merge Flex SDK with AIR 2.5 SDK. The AIR 2.5 download is restricted to the Android Prerelease program members, you can sign up here. Finally configure FDT’s preferences to use the new Flex SDK location.

Please, refer to the official documentation to know how to setup your Android virtual devices and emulator if you want to debug your applications on the SDK emulator first… We will focus just on compiling the apk (Android installable) file we need to test the application on a real device.

The project

The project will be a simple, standard AIR project. The basic structure includes the app-xml descriptor, the main class file and icons we need for our application. Be sure to change your application descriptor namespace to include “2.5″:

[cce_xml]<application xmlns=”http://ns.adobe.com/air/application/2.5″>[/cce_xml]

and the “initialWindow” visible flag is set to true:

[cce_xml]<initialWindow>

<visible>true</visible>

</initialWindow>[/cce_xml]

Now we have our project ready to be compiled and packaged. This should be the most boring part but I was able to quickly adapt a great ANT file shared from Jonathan Campos in a recent post.

Basically it consist in a total of three files; base.properties, build.properties and build.xml. The first two are just storing all path variables we’ll need to compile (SDKs, source files, assets location etc…), while build.xml takes care of compiling the swf, create a proper certificate, package the apk file for us and install on device too!

You just need to change build.properties to fit your setup:

[cce]# Flex SDK File Location on your computer
FLEX_HOME=/Users/Shared/flex_sdk_4.1.0.16076
SDK_VERSION=4.1.0.16076
#Android SDK Folder on your computer
ANDROID_SDK=/usr/tools/android-sdk-mac_86

#App Settings
APP_NAME=MyFirstAndroid

#compiler flags
LOCALE=en_US
DEBUG_FLAG=false

#Certificate
CERT_PASSWORD=yourPass
CERT_NAME=CertName
CERT_ORG_UNIT=Software Development
CERT_ORG_NAME=OrgName
STORETYPE=pkcs12
KEYSTORE=cert.p12
CERT_COUNTRY=IT
CERT_KEY_TYPE=2048-RSA[/cce]

That’s all! You can either run ANT file from command line of from Eclipse. Below you can see a picture showing how your project should look like:

Download and test!

I know, it’s a little boring to set up all this stuff before actually starting coding the good things. To solve this problem I uploaded a template project on google code for you to check out and use as base code for your next AIR Android killer app, enjoy:

https://code.google.com/p/air-on-android-with-fdt/

Feel free to send me your comments and suggestions!

Related Links:

http://www.fdt.powerflasher.com/ (FDT)
http://www.eclipse.org/downloads/ (Eclipse)
http://developer.android.com/sdk/index.html (Android SDK)
http://labs.adobe.com/technologies/air2/android/ (Android prerelease program
http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4 (Flex 4.1 SDK)
http://unitedmindset.com/jonbcampos/2010/07/19/android-mobile-development/ (Original ant file)

Comments

comments

2 Responses to “How to build your first AIR4Android application using FDT and Eclipse”
  1. Tonsula August 23, 2010
  2. AIR4Android December 31, 2010

Leave a Reply

Your email address will not be published.


*