Creating a Flash Builder Android Project

This post and it’s brother Creating a Flash Professional Android Project are going to be really short and sweet. I just want to make sure that there are no places for questions.

If you are starting with this post I recommend actually starting with a previous post introducing AIR for Android Development. There is a ANT file there that you will want to have.

FYI: All these steps are also available in Developing AIR Apps for Android PDF provided by Adobe.


Unlike Flash Professional we won’t be able to create an .apk file from our IDE. We can debug from the Flash Builder IDE, as shown by Renaun. That being said, that is where my ANT build file is even more helpful as it can package your application into a .apk file quickly for you.

Let’s set up this project.

Step 1: Startup
Create a new Flash Builder Project. File > New > Flex Project.

Step 2: Project Settings

Make sure the application type is Adobe AIR and that you are using the SDK that you created with the AIR 2.5 SDK.

Then click next twice or until you get to this screen.

Change your main application file to “[Your Application Name].as”. By default it will try to create an MXML file, but as we are trying to make an AS3 project we need to change the file extension to being “.as”.

It’s also good practice to change your application ID to be something a bit more unique – I always just add in reverse domain extension to it.

Click Finish

Step 3: Program
You should now have an application that looks like this:

package
{
    import flash.display.Sprite;

    public class HelloWorld extends Sprite
    {
        public function HelloWorld()
        {

        }
    }
}

You can keep programming your application to whatever you want. As I just want a quick application that shows Hello World so that we can continue, my application is going to be very simple.

My Application:

package
{
    import flash.display.Sprite;
    import flash.text.TextField;

    public class HelloWorld extends Sprite
    {
        public function HelloWorld()
        {
            var textField:TextField = new TextField();
            textField.text = "Hello World";
            stage.addChild(textField);
        }
    }
}

Step 4: Setup your descriptor file
First thing you should do is make sure that your application descriptor namespace includes “2.5″:

<application xmlns="http://ns.adobe.com/air/application/2.5">

If you are using the right SDK, this shouldn’t be an issue.

We only need to change a few attributes in the application descriptor file to get things going. Any other changes that we need to make will be more specific for your application.

In the “initialWindow” tag find “visible”. Make sure it is set to true.

Now find “supportedProfiles”, set this to mobileDevice.

Now go to the “content” tag and change it to “[Your Application Name].swf”. Flash Builder typically switches this name out for us, and I could do it in my ANT file. But I can be lazy at times and would prefer just to set this value. Especially since this application descriptor belongs to the one specific application.

Step 5: Package your application
Your application is now ready to be changed to a .apk file for release. This is also when I will diverge from the Adobe PDF. See, I don’t like command line. So I created that nifty little ANT file to do everything I need. Now go get that ANT file and add it into your project and make any changes necessary to the build.properties as described previously in the last post.

With the settings changed to your specific computer we are good to go. You can either run an ANT file from command line or from your IDE.

From the IDE:

Here I right-clicked on the build folder and went to Run As.

Or from your command line you can run the ant file. Just “change directory” to your project holding the build.xml. Here you can type in one of two commands.

[Hello World Directory] $ ant
[Hello World Directory] $ ant -buildfile build.xml build

Both mean the same thing as the build target is the default target in ANT and the build.xml is the default file. If you wanted to run a different target you could.

To run get_devices

[Hello World Directory] $ ant -buildfile build.xml get_devices

To run start_up_manager

[Hello World Directory] $ ant -buildfile build.xml startup_manager

After you run the build target you are good to go. The ANT file will spit out your .apk file in a release folder. That’s it, you are ready to get away from the Actionscript and into the Android release process.

Finally, the FXP file ready for Import.
AndroidTest.fxp

Share

Comments (52)

[...] This post was mentioned on Twitter by tony murphy and Ultra Red, karannnnnnnnnnn3. karannnnnnnnnnn3 said: Creating a Flash Builder Android Project: This post and it’s brother Creating a Flash Professional Android Project… http://bit.ly/cocMCo [...]

[...] – Building the Hello World Application in Flash Builder [...]

Javier JulioJuly 22nd, 2010 at 9:32 am

First off a huge thanks Jon! I’ve come very far with your tutorials but running into a few problems. I have everything installed and the project setup. My issue is a build failure with ANT. I’m getting the following error:

Buildfile: /Users/JavierJulio/Projects/MobileTest/build.xml

BUILD FAILED
/Users/JavierJulio/Projects/MobileTest/build.xml:13: taskdef class flex.ant.MxmlcTask cannot be found

Total time: 124 milliseconds

I’ve installed JDT for my Eclipse install so I’m running the ANT build from Eclipse. I don’t understand though why it can’t find the MXMLC task. I have everything pointed to the right folder. Any ideas what could be wrong? I’ve double checked and my FLEX_HOME and FLEX_TASKS variables are correct.

FLEX_HOME=/Applications/Adobe\ Flash\ Builder\ 4/sdks/4.1.0_AIR_2.5
FLEX_TASKS=${FLEX_HOME}/ant/lib/flexTasks.jar

Verified that these file paths auto completed in Terminal. I was reading the README file in the sdk’s ant folder and it mentioned including “flexTasks.tasks” as one of the taskdefs. Also that ant folder contains a build.xml file that I can see is defining the flexTasks. Shouldn’t I be referencing that somewhere to make sure its getting built? I know I’m just missing the last piece to run this. Hope you can help. Thanks!

Jonathan CamposJuly 22nd, 2010 at 9:49 am

@Javier hmmm, that is odd. Have to ask, have you made any other changes that I should know about?

Javier JulioJuly 22nd, 2010 at 9:56 am

No I just downloaded your build.zip and change the file paths to match mine in the properties files and then changed the app name to match what I have which is MobileTest. I noticed the build.xml file you have just has:

But when going to the /{fbinstall}/sdks/{41wAIR2.5}/ant/ folder I opened the README file and read that apparently I need to do the following:

Place flexTasks.jar into the lib directory of your Ant installation.
Alternatively, you can specify the location of the JAR file as an
argument to Ant, as the follow example shows:

ant -lib /flexTasks.jar .

In addition to this, you must include the following line in any build
file that uses the mxmlc or asc tasks:

.

Have you done this before? I tried running the ant lib command above but getting errors on finding flexTasks and if I just include the taskdef doesn’t seem to do anything. Do you remember doing anything that was mentioned above?

Jonathan CamposJuly 22nd, 2010 at 9:59 am

@Javiar Do you know what version of ANT you are using?

Jonathan CamposJuly 22nd, 2010 at 11:50 am

We figured out @Javier’s issue offline. Make sure to set your FLEX_HOME path correctly ;)

[...] post and it’s brother Creating a Flash Builder Android Project are going to be really short and sweet. I just want to make sure that there are no places for [...]

jgondekAugust 31st, 2010 at 4:13 pm

Hi,

I’m having a problem when trying to debug on the device. When just building everything seems to go fine. These lines show up while building:

Buildfile: /Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/build.xml
debug_on_device:
-preclean:
[delete] Deleting directory /Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/release
-init:
[mkdir] Created dir: /Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/build
[mkdir] Created dir: /Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/release
-compile:
[mxmlc] Loading configuration file /Applications/Adobe Flash Builder 4/sdks/AIR 2.5 for Android/frameworks/air-config.xml
[mxmlc] Adobe Flex Compiler (mxmlc)
[mxmlc] Version 4.1.0 build 16076
[mxmlc] Copyright (c) 2004-2009 Adobe Systems, Inc. All rights reserved.
[mxmlc] command line: Error: configuration variable ‘file-specs’ value contains unknown token ‘app.file’

Any ideas of what is wrong?
[mxmlc] Use ‘mxmlc -help’ for information about using the command line.

BUILD FAILED
/Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/build.xml:277: The following error occurred while executing this line:
/Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/build.xml:50: mxmlc task failed.

Total time: 2 seconds

Jonathan CamposAugust 31st, 2010 at 4:21 pm

Interesting. What is the name of your application and what is the name of your application descriptor file?

Sound be something like: Main.as and Main-app.xml

jgondekAugust 31st, 2010 at 4:28 pm

Well,

none of those… Its TEST_AIR.as

Jonathan CamposAugust 31st, 2010 at 4:33 pm

Dang, I see what happened. I accidentally uploaded a build file before I added in the prompts to the targets. When I get to a computer later I’ll upload the correct version. If you are comfortable with ANT you can add in the code by adding prompting to build or set the value in build.properties. Sorry for that.

Jonathan CamposAugust 31st, 2010 at 4:34 pm

That is okay for it to be TEST_AIR.as as long as you have the application descriptor file set to TEST_AIR-app.xml. But there is still an issue that I need to update

jgondekAugust 31st, 2010 at 4:40 pm

Well,

I’ve worked with AIR before and work in AS3 all the time but never used Ant. In my country it’s 11:33 pm and I should be sleeping now, but I just bought some little device that doesn’t let me go to sleep :P

Thank you for a fast response, I’ll check if it helped after work (in next 14 hours I think).

Jonathan CamposAugust 31st, 2010 at 5:18 pm

The quick fix is to change

name=”debug_on_device”

To

name=”debug_on_device” depends=”-prompt_for_app”

I will post the fix in a few hours

Jonathan CamposSeptember 1st, 2010 at 12:07 am

@jgondek updated the files so they all work properly. however there is no easy plugin to the flash builder debug. All you debugging would need to be done via command line. not fun

jgondekSeptember 3rd, 2010 at 3:02 am

Hi,
now I’m getting this:

Buildfile: /Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/build.xml
install_debug_on_device:
-get_applications:
[echo] Application List:
[echo] – TEST_AIR.as
-prompt_for_app:

BUILD FAILED
/Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/build.xml:279: The following error occurred while executing this line:
/Users/jgondek/Adobe Flash Platform/Experiments/TEST_AIR/build.xml:132: java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM

Total time: 920 milliseconds

jgondekSeptember 3rd, 2010 at 3:43 am

Ok,

figured it out. Had to add JVM argument -d32.

Jonathan CamposSeptember 3rd, 2010 at 8:56 am

@jgondek Great to hear! That is an error definitely dependent on your workspace. Thanks for posting the solution. I’m sure it will help others.

LexaSeptember 10th, 2010 at 10:33 am

Hi :)
I’m getting error when trying install apk on the device.
==========
C:\[bla-bla]\android-sdk-windows\tools>adb install AndroidTest.apk
361 KB/s (977224 bytes in 2.638s)
pkg: /data/local/tmp/AndroidTest.apk
Failure [INSTALL_FAILED_INVALID_APK]
==========
adb logcat:
E/PackageManager( 72): Package air.AndroidTest has mismatched uid: 10036 on disk, 10040 in settings
==========
Other applications are installed without problems.

Jonathan CamposSeptember 10th, 2010 at 10:41 am

@lexa I’m guessing that the issue has something to do with your descriptor file. Have you made any changes?

LexaSeptember 13th, 2010 at 9:49 am

My descriptor file:
==========

AndroidTest
AndroidTest
AndroidTest
1

AndroidTest.swf
true

mobileDevice

Jonathan CamposSeptember 13th, 2010 at 9:52 am

@lexa sorry, I think wordpress swallowed some of your formatting. Try sending again. Also, I’ve uploaded some updates to the ANT file as recently as this morning. I would redownload and let me know what you find.

J

LexaSeptember 13th, 2010 at 9:52 am

ffffck :)
============
<?xml version="1.0" encoding="utf-8" standalone="no"?]
[application xmlns="http://ns.adobe.com/air/application/2.5"
[id]AndroidTest[/id]
[filename]AndroidTest[/filename]
[name]AndroidTest[/name]
[versionNumber]1[/versionNumber]
[initialWindow]
[content]AndroidTest.swf[/content]
[visible]true[/visible]
[/initialWindow]
[supportedProfiles]mobileDevice[/supportedProfiles]
[/application]

Jonathan CamposSeptember 13th, 2010 at 9:57 am

@lexa Also, which version of the AirAndroid SDK are you using? make sure to keep upgrading to the newest, current release is 9/09

Jonathan CamposSeptember 13th, 2010 at 10:03 am

@Lexa One last update. I had forgotten to push up the update for my build.properties and base.properties also. I don’t want to cause confusion so I just repushed up the entire build.zip. Hopefully this limits the confusion factor.

LexaSeptember 14th, 2010 at 7:20 am

All SDK, and build.xml has been updated, but…
“Package air.AndroidTest3 has mismatched uid: 10036 on disk, 10039 in settings”
Source code:
http://rapidshare.com/files/418989266/AndroidTest3.zip

Jonathan CamposSeptember 14th, 2010 at 9:00 am

@Lexa Looking at the code I can tell you’ve made a variety of changes to the original example. I’d recommend starting with the base example that I’ve given and build up from there.

LexaSeptember 14th, 2010 at 10:40 am

Basic example also does not install :)
To exclude all mistakes would you like to upload file of your HelloWorld project for download? So, I can try to compile and to install it.

Jonathan CamposSeptember 14th, 2010 at 11:10 am

@Lexa Added the FXP file to the end of the post

LexaSeptember 16th, 2010 at 4:17 am

The same error.

Jonathan CamposSeptember 16th, 2010 at 8:52 am

@Lexa I checked that project prior to releasing it. At this point I would say to double check your air sdk and then possibly contact adobe for assistance.

CameronSeptember 17th, 2010 at 3:22 pm

I followed the instructions above, and ran the ANT. It seems to finish, but I get no apk file. This is the last line in the console:
[copy] Copying 1 file to C:\Documents and Settings\Cameron\Adobe Flash Builder 4\WispMonDroid\build

Jonathan CamposSeptember 17th, 2010 at 3:26 pm

@Cameron what is the last target that is run? Can you give me more of your output?

CameronSeptember 17th, 2010 at 3:43 pm

Buildfile: C:\Documents and Settings\Cameron\Adobe Flash Builder 4\WispMonDroid\build.xml
build:
-preclean:
[delete] Deleting directory C:\Documents and Settings\Cameron\Adobe Flash Builder 4\WispMonDroid\build
[delete] Deleting directory C:\Documents and Settings\Cameron\Adobe Flash Builder 4\WispMonDroid\release
-init:
-compile:
[mxmlc] Loading configuration file C:\Program Files\Adobe\Adobe Flash Builder 4\sdks\4.0.0\frameworks\air-config.xml
[mxmlc] C:\Documents and Settings\Cameron\Adobe Flash Builder 4\WispMonDroid\build\WispMonDroid.swf (866 bytes)
-certificate:
-move_descriptor:
[copy] Copying 1 file to C:\Documents and Settings\Cameron\Adobe Flash Builder 4\WispMonDroid\build

Jonathan CamposSeptember 17th, 2010 at 3:49 pm

@Cameron Interesting. Are you sure that all your paths are correct? You also may want to try running the ant file with an additional “-verbose” flag and see if you get some more information about your build.

Jonathan CamposSeptember 17th, 2010 at 3:50 pm

@Cameron oh, and do you have an “assets” folder in your project? Some people have had that issue. I assume you do have that file in my script.

CameronSeptember 17th, 2010 at 4:37 pm

I rechecked the paths…look right to me. I moved the project too, but it didn’t help. Here is the verbose output:
… edited and shortened by jonbcampos
[copy] Copying C:\Android Projects\WispMon\src\WispMonDroid-app.xml to C:\Android Projects\WispMon\build\WispMonDroid-app.xml

Jonathan CamposSeptember 17th, 2010 at 4:42 pm

Do you have a build file? Is anything in it? Have you made any other changes to the project?

Jonathan CamposSeptember 17th, 2010 at 4:44 pm

@Cameron email off list at jonbcampos [at] gmail

[...] Creating a Flash Builder Android Project [...]

vicOctober 13th, 2010 at 2:26 pm

I’m able to compile and get the apk file, but I’m unable to run the start up manager.

ant -buildfile build.xml startup_manager

I receive this error.

Execute failed: java.io.IOException: Cannot run program “/usr/lib/android-sdk-mac_86/tools/android”: error=2, No such file or directory

I’ve verified that the path to the sdk is correct. Any ideas?

Jonathan CamposOctober 13th, 2010 at 2:30 pm

@vic are you on windows or mac?

JulienJanuary 13th, 2011 at 8:26 am

Hi,
Thanks for this really coll tutorial. I have a similar issue while trying to build the app as Javier.

Terminal log:

Buildfile: build.xml

BUILD FAILED
/Volumes/UserSpace/Users/jmandart1016/Documents/Adobe Flash Builder 4/HelloWorld/build.xml:12: taskdef class flex.ant.MxmlcTask cannot be found

Total time: 0 seconds

I can see that the error is from line 12 in build.xml

but I don’t know how to fix this.

regards,

jonbcamposJanuary 13th, 2011 at 9:50 am

@julien Same questions that I had for Javier. Have you made any changes to the script? Are you sure your paths are right? Feel free to email me off topic if you like. jonbcampos [ at ] gmail.

RhysJanuary 17th, 2011 at 8:41 am

ok, hey guys, ive tried to follow this tutorial a few times with little luck, im hoping someone can help, im sure im just forgetting something, the problem im getting is this…….

build.xml:31: The following error occurred while executing this line:

build.xml:81: Java returned: 12

i cleared a few other build errors before this, im wondering is this maybe down to not having the JDK installed??

jonbcamposJanuary 17th, 2011 at 9:40 am

@Rhys do you not have Java in your system at all? You definitely should have Java 1.6 installed at least. Let me know what is going on.

RhysJanuary 17th, 2011 at 10:36 am

Hey thanks for getting back so quick, nice, ummm, well i would assume that some sort of java system is already installed as i can run java in browser (??) but what i have done now is download java and install from this location http://www.java.com/en/download/inc/windows_new_xpi.jsp <- now i know this is not the JDK should i install the JDK instead because i saw in some other tutorials they had said you need the JDK, so im gonna let that install and will get back to you wether it works or not, thanks again for help

RhysJanuary 17th, 2011 at 10:41 am

I bloody love you man!!!!!!!!!!! ok so i think installing java helped :) lol also i had the content tag pointing to an .as file rather than a .swf, what more can i say I’m an idiot and you are a true master :D , Thanks again, now lets see if it works on me Streak!!!

jonbcamposJanuary 17th, 2011 at 10:42 am

@Rhys LOL Awesome. I’m glad you’ve got it going. Now you can do some really fun stuff :)

RhysJanuary 20th, 2011 at 5:04 am

Hey again jon, hope your well, thanks again for the help. Ive run into a little problem with ANT and as I’m fairly new to it I was hoping you might be able to help?

So I’m sticking with the A’s for the moment I’m using ANT for a AIR Android project and I wanted to use a third-party library -> Away3D, see all A’s :)

So i have a problem with ANT in terms of using a third-party library, if i debug from within flash builder it all works fine, however if i try to do a build via ANT it has problems withh all the Away3D packages / class files in that i think it cant find them, was wondering if i need to set up some paths in ANT to point to third party libraries??

Any help is much appreciated man, heres the sort of thing ANT throws back to me on build -> col: 26 Error: Type was not found or was not a compile-time constant: ObjectContainer3D.

Thanks again in advance,
cheers – Rhys

jonbcamposJanuary 20th, 2011 at 10:04 am

@Rhys You can definitely include the 3rd party library, but how you include the library is dependent on how you want to link the library. If you are using a SWC then it is pretty simple and you just need to either point to the exact swc or the swc folder – libs is already set up for that in my ANT build script.

If you want to link a folder with code then you will need to add another source code folder path to include that.

Either way I’d say to read through the docs and see how it is done. http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_1.html

Leave a comment

Your comment