How to Create Adobe AIR for Android using FlashDevelop

If you’re a Flash developer who wants to start developing Flash with Android device, then this post might help you to get started πŸ˜‰

Adobe AIR SDK 2.5 has been released since last October which includes Adobe AIR for Android packager. Most help avaialble are for Flash Builder 4 or Flash CS5, only a few using FlashDevelop.

This post is a step-by-step instruction for creating Actionscript 3 Flash project for Android, based on Adobe’s guide for creating Adobe AIR application for Android with Flex SDK.?This will not compatible for For Flex Mobile (Flex Hero/4.5 SDK). Stay tune since I’ll write one later πŸ˜‰
Update (21st Dec):For using Flex Hero on FlashDevelop, see my latest post πŸ™‚

Before you start, you can download the whole project and source code of this post from here πŸ˜‰

1. Install Adobe AIR 2.5 SDK

  • Download AIR SDK 2.5 at http://www.adobe.com/go/air_sdk
  • Make sure you already have Flex SDK installed on your machine. I use Flex SDK 4.1 for this example.
  • Extract the AIR SDK zip file to the Flex SDK folder. This will overwrite all AIR-related files on Flex SDK 4.1. Your Flex SDK 4.1 will have AIR 2.5 installed!
  • Make sure that you have set PATH environment variable to {flex_4_folder}bin. For example, c:flex4.1bin, if you installed the SDK on c:flex4.1
  • To make sure that you have AIR 2.5 installed, type adt -version from command line. You’ll get “2.5.XXXXXX”

2. Install Android SDK
You have to download and install the Android SDK even though you’re using Adobe AIR to create application. The Android SDK is used mainly for creating the Android package (APK) and also to install the application directly to your device.

Check Adobe’s Android Setup for help or directly to Android Developer installation guide.

Make sure you also set the environment path to {android_sdk_folder}tools.
Update: Since the SDK r08, set the path to {android_sdk_folder}platform-tools instead, so you can acccess the command adb from anywhere.

3. Create AIR project using Flash Develop

  • Open FlashDevelop. Create a new project
  • Choose AIR AS3 Projector. This will create a project with Main.as file.
  • Edit your Main class (don’t forget to change the package name πŸ˜‰ ):
package com.abiyasa
{
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;
	import flash.text.TextField;

	public class Main extends Sprite
	{
		public function Main():void
		{
			this.stage.align = StageAlign.TOP_LEFT;
			this.stage.scaleMode = StageScaleMode.NO_SCALE;

			var myText:TextField = new TextField();
			myText.text = "ohai, im in ur android, sending my text";
			myText.width = 240;
			myText.backgroundColor = 0xCCCCCC;
			myText.background = true;

			this.addChild(myText);
		}
	}
}

4. Change the Application.XML

  • Change the xmlns (AIR 1.5) to xmlns="http://ns.adobe.com/air/application/2.5"
  • Change <version>1.0</version> to <versionNumber>1.0</versionNumber>
  • Add <supportedProfiles>mobileDevice</supportedProfiles>
  • Add Android manifest. Just like every Android apps (native or Adobe AIR), we have to declare what phone feature we are going to use (e.g Internet, GPS, Camera, touch screen, screen types, …). This is important to if you’re going to submit ur app to Android Market
  • for this example, we don’t use any, but let’s give the very basic permission
  • Here is the full application.XML
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/2.5">

	<id>com.abiyasa.AirAndroidTest2</id>
	<versionNumber>0.5.0</versionNumber>
	<filename>AirAndroidTest2</filename> 

	<name>AirAndroidTest2</name>
	<description></description>
	<copyright></copyright> 

	<initialWindow>
		<title>AirAndroidTest2</title>
		<content>AirAndroidTest2.swf</content>
		<systemChrome>standard</systemChrome>
		<transparent>false</transparent>
		<visible>true</visible>
		<minimizable>true</minimizable>
		<maximizable>true</maximizable>
		<resizable>true</resizable> 

		<!-- Note: set autoOrients to false and aspectRatio to landscape to lock app on landscape mode -->
		<autoOrients>true</autoOrients>
		<!--<aspectRatio>landscape</aspectRatio>-->
	</initialWindow> 

	<supportedProfiles>mobileDevice</supportedProfiles>	

	<!-- Specify Android specific tags that get passed to AndroidManifest.xml file. -->
	<android>
	<manifestAdditions>
		  <![CDATA[
			<manifest android:installLocation="auto">
				<!-- Added for Internet and debugging support -->
				<uses-permission android:name="android.permission.INTERNET"/>

				<uses-configuration android:reqFiveWayNav="true"/>
				<supports-screens android:normalScreens="true"/>
				<uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>

				<application android:enabled="true">
					<activity android:excludeFromRecents="false">
						<intent-filter>
						<action android:name="android.intent.action.MAIN"/>
						<category android:name="android.intent.category.LAUNCHER"/>
						</intent-filter>
					</activity>
				</application>
			</manifest>
		  ]]>
	  </manifestAdditions>
	</android>
</application>

5. Run on device simulator (using ADL)
At this stage, try to compile and run. Press Ctrl-Enter or press F5. If everything is allright, your Flash app will be shown as a popup, just like normal AIR application. However, the simulator on ADL will look a little bit different.

Just check the menu ‘Device’, and there are options to simulate screen rotation. Try to click ‘Rotate Left’ or ‘Rotate Right’

6. Create icons
Before we create the Android package (APK), there are two things we should prepare: icons and digital certificate. We should provide 3 sizes of icon:36×36, 48×48, and 72×72 so your app’s icon can be displayed nicely on different screen size. Google has a very good guideline for icons. Check it out here.

If you want to create simple icons, Google has a simple web tool for that πŸ˜‰

Once you have the icons, put them on folder icons and put the folder icons inside the bin folder (where you SWF file generated). This is to make the packaging process easier.

Then we need to edit the application.xml to include our icons. Add these line below the </android> line:

<icon>
    <image36x36>icons/icon36.png</image36x36>
    <image48x48>icons/icon48.png</image48x48>
    <image72x72>icons/icon72.png</image72x72>
</icon>

7. Create self-signed certificate
The last thing that you should prepare is a digital certificate. The certificate will be used to sign your application so the user knows that the app is coming from you, not from someone else. This is also the requirement if you want to publish your game to Android Market.

Luckily, you can create your own certificate (self-signed certificate) for free and you don’t have to use the pay one. I remember when we were using J2ME and Symbian that only paid certificate was accepted.

If you already have or created your own certificate (from previous project), you can skip this step and use your certificate for creating APK file.

  • To create a certificate just execute the this command (one line):
    adt -certificate -cn SelfSigned -o "Green Game Company" -validityPeriod 25 1024-RSA myCertificate.p12 test123
  • test123 is the password for your certificate. Change it to your password and remember that you will use this password once more during package creation.
  • Change "Green Game Company" with your company name or your name. Double Quote is included if you game company name has spaces.
  • Once executing the command, a certificate file called myCertificate.p12 will be created.
  • You only need to create certificate ONCE! If you already have the file, you don’t have to create it. Just use the same certificate file to create the APK
  • Make sure you always use the same certificate for each application. You can even have one certificate for every apps you develop.
  • There are some rules for certifcate when to apply android market. For testing on your device this is not required. See Android publishing guide for more details

8. Create APK

  • Go to bin folder (where you have the SWF file and icons folder) and type this command (one line):
    adt -package -target apk -storetype pkcs12 -keystore ..myCertificate.p12 -storepass test123 AirOnAndroid.apk ..application.xml AirOnAndroid.swf icons
  • The adt command uses the certificate file, application.xml, swf, and icons to create the APK.
  • The 'storepass test123' paramater is the same password for creating the certificate

9. Send it to your Android
There is nothing can beat testing your app on real device. Even Android developers test their app on device. There are emulators included in Android SDK but it took minutes just to get the emulator started and it does not reflect the speed and rendering on real device.

  • First, connect your device with USB. You may need to install the driver first.
  • We’re going to use adb tools from Android SDK. You need to have to inculde the Android tools folder to you environment path.
  • Type adb devices to see if your device connected. This command will list the connected devices (or even emulator) with your computer. Your device may appears as something like ‘I7500wJLU2AuEy0’. AT least, the list should not empty πŸ˜‰
  • Go to the folder bin (where you have your APK file generated) and type adb install AirOnAndroid.apk
  • Open you Android phone. You’ll see you app’s icon. Open it πŸ™‚

Don’t forget that you can also download the whole source code of this post from here. I also include the batch file to create certificate files and the APK file πŸ˜‰

Some very good Links:

25 thoughts on “How to Create Adobe AIR for Android using FlashDevelop

  1. I’d just like to announce that this is my first time posting a comment on a blog. Thank you so much for the valuable information! I’m trying to set up an environment for air to android but I’m reluctant to move forward if a more up to date solution is available. I just have a couple questions:

    1. Is there a way to integrate FlashDevelop with Hero/4.5 and air 2.5.1 that I coincidentally have not found?

    2. I’m fairly new to air but is it possible to deploy pure as3( e.g. non-flex ) modular swfs for air to android applications – I’m shooting for a completely dynamic modular architecture with a shell app that maxes something like 25k.

    You might be the only one that can help me. I don’t know what the big hype is with FlashBuilder, but FlashDevelop deserves greater focus!!. What do you think… should I just move forward with the flex 4.1 and air 2.5 for now or do you know of any other resources that could help me? Thanks again and I’ll check back.

    faj

    • Hi Faj! Thanks for commenting my Blog.

      1. Yes, you can make Flex 4.5 + AIR app using FlashDevelop. I’m planning to make post for that, so stay tune πŸ˜‰
      2. Yes, absolutely you can make pure AS3 AIR application.

      If you’re targeting Android application development, then Flex 4.5 is the best choice. It has a lot of mobile-optimized components like memory & speed optimization, components re-sized to fit for mobile or TV screen, UI designed to be used with touch screen, …. The release version will be somewhen on 2011 but you can start playing around with the beta/preview. But if your main target is ‘normal’ desktop application, then you can start with Flex 4.1 for now πŸ˜‰

  2. When i install your demo application on the emulator i get this error message:

    The application Air On Android (process com.abiyasa.AirOnAndroid) has stopped unexpectedly. Please try again.

    Any help?

  3. THANKYOU SO MUCH for this tutorial… I’ve spent days wading through other information on the web and didn’t even come close to success until I found your blog.

    For the benefit of other readers, there were one or two sticking points which I overcame…

    1. The filenames are CASE-SENSITIVE. I kept getting Error 302 until I realised I had dropped a capital letter in one of the parameters.

    2. If you’re compiling for an emulator, you have to use “apk-emulator” instead of “apk” otherwise you get “INVALID APK” when trying to install.

    Thanks again!

      • Hey there – I posted too soon before haha (I was just happy to get the apk installed!)

        So, I’ve installed the apk on the emulator, but all I get when I run it is a big old blank screen!

        I’m using Android 2.2 and the AIR Runtime 2.5. And my small test application works just fine when I run it in AIR on my pc.

        Have you had any success running apks on the emulator?

        • I’ve tried the emulator but it was very slow. I’m not sure what’s the problem of blank screen, but you can try these:

          – make sure the target is defined as ‘apk-emulator’ on your adt command.

          – Sometimes it could take long time for your app to be displayed (like 10s). While waiting, Adobe AIR doesn’t show any splash image

          – Try to install Adobe AIR runtime specially made for emulator (not the one for real Android device). You could get it from your Flex SDK, inside the folder {flex_sdk_path}runtimesairandroidemulator

  4. Hey,
    Nice I am still trying with it πŸ™‚
    I have a question you said to rotate the simulator view just press on device menu and choose any of the rotate but both of them are disable so what can I do ??

  5. I tried also to build the apk file and it always says that

    D:Own ProgramsFlex SDKbinmyprojectsTestingProjectAirapplication.xml: error
    302: Root content TestingProjectAir.swf is missing from package

    so I dont know what is that ??? also when I open adobe air page u suggested after installing the android sdk

    it says:

    If you plan to run the AIR development utilities from the command line, rather than an IDE, you can set the AIR_ANDROID_SDK_HOME environment variable to reference the Android SDK folder. If you do not set this environment variable, you must specify the path to the Android SDK in the -platformsdk argument on the ADT command line.

    I dont know how to set environment variable also when I tried to add -platformsdk command it tells me it isnt supported ??? thats wired so hope u can help me πŸ™‚

    • hi again πŸ˜‰ ,

      Make sure that you mention the TestingProjectAir.swf inside your application.xml (property and ), including the full package name on .

      You don’t have to define AIR_ANDROID_SDK_HOME unless you want to use adt tool to send apk to android device. Instead, we directly use the tool from android SDK (adb command line). But if you define AIR_ANDROID_SDK_HOME, you can use adt command to do everything (install, execute, and even debug apk from your Android device), no need to use adb.

      Try to google ‘set path environment’ and set AIR_ANDROID_SDK_HOME to your Android SDK’s directory. Enjoy πŸ˜‰

  6. Hey πŸ™‚ me again πŸ™‚
    after I define the enviroment variable the apk is released
    I launched the emulator and used installation command it starts installation then it tells me that

    Failure [INSTALL_FAILED_INVALID_APK]

    which i dont know why ??

    • Hey again πŸ™‚
      It might be that the APK is not build correctly. Many things could cause this:
      – Manifest file not defined correctly,
      – Wrong certificate,
      – …

      I am not so sure..

  7. Hey again πŸ˜€
    I know I am a bit headache to you πŸ™‚ but I want really to develop games for mobile devices πŸ™‚ and using AS3 is amazing πŸ˜€

    another question when I place these tags

    false
    landscape

    in intail window the result must be Adobe air emulator in landscape mode but the result is Adobe air emulator in portrait :S which sucks I tried also to use portrait but it keeps the same :S which sucks

    Another question the default resolution of the adobe air emulator is ??x?? is it the same as the android which is 480×800 or what ?? sorry for disturbance and thnx inadvance πŸ™‚

    • Hi again πŸ™‚
      That’s the sucky part of Adobe AIR emulator. You can only simulate the portrait but not landscape.
      I think the size is 480×800 and you can configure it as well. I tried to change the emulator size but it didn’t work 😐

      I think it’s worth it to have a real device to test with.

  8. Hey πŸ˜€
    I may look like spammer by sending this again πŸ™‚
    I changed the platform to android 2.3.3 emulator so when I install the apk it is installed and found it in the main menu
    but needed adobe air to work
    I finally managed to install adobe air on the emulator and when launching the program it says the following in a pop up menu

    The application TestingProjectAir (process air.com.amidos.TestingProjectAir) has stopped unexpectedly.
    Please try again.

    then a button for Force Closing :S

    I tried lots of several ways but I couldnt make it :S

    • Hello again πŸ˜‰
      ‘Has stopped unexpectedly’ error message could mean many things πŸ™
      But you can try to activate Android logcat tools to see what cause the error. Try this, if you don’t install Eclipse:
      – Make sure the Emulator has been started and ready to execute your application (your app has been installed)
      – open command prompt, and type ‘adb logcat’
      – If this is correct, you command prompt will be flooded by a lot of text message. Don’t panic, it’s normal πŸ˜‰ Logcat will log every event on emulator or even real Android device.
      – go back to your emulator, and start your application. If you’re lucky, you can see the error or Exception error

  9. Hey I tried that and reading the logging and dont understand why it terminate here what happens at the starting of the app everything looks nicely working till it says.

    W/WindowManager{ 69}: Window freeze timeout expired.
    then it force clearing all the settings
    then it says
    W/WindowManager( 69): Launch timeout has expired, giving up wake lock!
    then some Blah! Blah! Blah!
    and found
    E/AndroidRuntime( 578): FATAL EXCEPTION: main
    E/AndroidRuntime( 578): java.lang.UnsatisfiedLinkError: nativeSetVisisble
    E/AndroidRuntime( 578): at com.adobe.air.AndroidActivityWrapper.nativeSetVisible(Native Method).

    then lots of Blah! Blah! Blah! πŸ˜€

    hey is that understandable or need more logging details πŸ˜€

  10. All I can say that once you have a Flash game binary you can use Andaired demo version to build a APK for testing.

  11. Pingback: Starling, FlashDevelop, Android and Me (Us? Meh) | puhri || λΏŒλ¦¬λ°•κΈ° ν•˜λ‹€

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.