UPDATE: The application descriptor file has an additional tag — "versionNumber", which is required in order to export a native .apk file.
In my previous post, I showed how to build an Android AIR application in Flash CS5, and how to deploy it on an Android device. In this post I will show you how to create an Android application using Flash builder 4. If you read my previous post you should have already downloaded the required SKDs (AIR 2.5 for Android and Android SDK).
At this point, what you need to do, is to update the AIR version inside your Flex SDK, to AIR 2.5, which is the version you will have to use in order to compile apps for android. You can find your Flex SDK inside your Flash Builder 4 installation folder (Windows: Program Files/Adobe/Adobe Flash Builder 4/sdks/), (Mac: /Applications/Adobe Flash Builder 4/sdks/). To do this, check "How to overlay AIR for use with the Flex SDK".

Now that your SDK is ready, open Flash Builder and create a new Flex Project. Note that in this project we will need to use the Flex SDK we just set up. As "Application type" choose "Desktop", and press Next, you can leave the output folder as is. Now, we need to use pure ActionScript in this project so we won't use mxml files. So now press the next button again, and you will see the last project wizard dialogue. Give a look into the Main application file field. It is specifying an mxml file, but since we are going to use pure ActionScript, we need to change the extension to .as. So if the application file is FlashBuilderAndroidDemo.mxml, it will have to be FlashBuilderAndroidDemo.as (see the image below).

Now press finish and here you go... You have got your application ActionScript class ready to be edited.
Now create a TextField instance and put it on the stage. Note that in an ordinary AIR application you should create a NativeWindow if you are using this workflow, but in this case, since you are developing for an Android phone, you will just extend the Sprite Class (as it were a Flash Player project). However keep in mind that you might set the scaleMode of your stage to NO_SCALE (if you need to).
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
public class FlashBuilderAndroidDemo extends Sprite {
public function FlashBuilderAndroidDemo() {
stage.scaleMode = StageScaleMode.NO_SCALE;
var tf:TextField = new TextField();
var ts:TextFormat = new TextFormat();
ts.size = 20;
tf.defaultTextFormat = ts;
tf.border = true;
tf.x = 50;
tf.y = 50;
tf.width = 400;
tf.height = 40;
tf.text = "Tap here to input";
tf.type = TextFieldType.INPUT;
addChild(tf);
}
}
}
Here you are. Now what you need to do, is to install the application on your device or on an Android Emulator. I will explain how to deploy application on emulators in the next part of this article, for now make sure that your device is plugged to your computer's USB port and make sure it is read by writing the following code to the command line:
$ adb devices
You should now get the device ID in your command line screen. Now you will have to convert the SWF file you created into a native Android application (.apk file). So cd into the "bin-debug" directory of this project and write:
$ sudo adt -package -target apk -storetype pkcs12 -keystore cert.p12 FlashBuilderAndroidDemo.apk
FlashBuilderAndroidDemo-app.xml FlashBuilderAndroidDemo.swf
Note: use sudo only if you are using a mac.
As you can see I am passing to the -keystore parameter a self-signed certificate file name — in this case cert.p12 was created using Flash Builder in the same way you would do as you were creating an ordinary AIR app for desktop — after that the name of the output .apk file, the application descriptor xml file and finally the .swf file to convert. You will be asked to input a password which is the certificate password (if you used sudo, you will be prompted first for the user password). If everything went OK, you should see an .apk file in your bin-debug directory. Let's install it on the device:
$ adb install FlashBuilderAndroidDemo.apks
You should get a success message on your command line screen. Now grab your Android device and start the application. You should see the TextField we created. Tap it. Since it is of type "input" you should see the android soft keyboard popping up from the bottom of your screen.
Stay tuned for part 2, where I will show you how to deploy AIR apps on an emulator, for who doesn't have a device yet.
Good Luck!