rss twitter

AIR2 and FDT4 (M4) – A detailed Walkthrough with ANT

Hello,
someone might remember an older post on Beautify Code which has shown how to successfully create an AIR application certificate, publish the project and then package it to an .air file, which can be installed and run. Now here's the 2010 update, working with AIR2 and FDT4 (using an ANT-Build) and some major changes.

Table of Content:

  1. Introduction
  2. Required Downloads
  3. Creating an AIR2 Project in FDT4
  4. Application Descriptor
  5. A powerful ANT-Build
  6. Digitally Signing / Certificates
  7. Most Common Errors
  8. Summary & Sample-Project

Introduction:

Creating an AIR-Application requires different tasks. First of all we need to publish an SWF which represents our content. Secondly we need to create a certificate and at last we have to package the application into an .air file. By going through these three steps you will get known to an Application Descriptor, a very handy ANT-Build file, creating a certificate and what most of these really cryptic error messages mean. In the end you are able to release an AIR application with FDT 4 which can be quickly compiled as an Android-App or a Webdeploy as well by just changing the Descriptor.

Required Downloads:

Okay, firstly everybody get FDT4. Seriously, you cannot find anything better out there. :) The only thing what bothered me most at FDT4 was the still remaining bad workflow concerning AIR-Applications. Now I know better and as you can imagine - after writing this article I can't even complain anymore.

Secondly, you need a Flex SDK which supports AIR 2. I am currently working with 4.1.0.16076. Download it on Adobe Open Source and unpack it somewhere you like to. I prefer sticking my SDKs together so I've taken FDT's plugins/ folder which already contains the shipped ones.

Besides we need an iconpackage containing different sizes so we can use them as tray- and applicationicon. Download AIRTest_assets.zip and unpack the assets folder to your project's root directory. There is already set up a settings folder within, which later will be used for our certificate - so just keep it.

Creating an AIR2 Project in FDT4:

Thankfully FDT4 implemented Project Templates which easily allows us to create an AIR Project. Well, sounds good. Unfortunately the current build (maybe they'll change it till release) uses the Flex 4.0 SDK which does not support AIR 2. That means we have to change the SDK but luckily again this has been simplified a lot as well in FDT4. The following screenshots demonstrate how to add a new SDK and then chose it for the new project.

Create a new project with the desktop AIR Application template using Flex 4. Give it a name, specify your project location and continue by pressing "Next". On the following screen you see the already installed SDKs which have been shipped with FDT4. By clicking on "Add" you can install a new one - in our case Flex 4.1.

Create Project with AIR Template
Add a new SDK









Specify the SDK directory, which will make FDT to initialize the containing swc files. As it's finished, give your SDK a name and confirm with "Okay". Close the "Installed SDKs" window and you are back at the project settings where you can chose your new SDK in the pulldown. If everything went fine you now should see that this SDK is supporting AIR 2.0.2.

Specify the SDK directoryUse this SDK for the new project









Finally there has been a new AIR project created on our workspace and we're ready to set up a class to be compiled. So as we all know: Rightclick on your src folder, create new AS3 class and so on. Here's mine:

Actionscript:
  1. package {
  2.     import flash.display.Sprite;
  3.     import flash.text.TextField;
  4.     import flash.text.TextFieldAutoSize;
  5.  
  6.     /**
  7.      * @author Marvin
  8.      */
  9.     
  10.     public class AirTest extends Sprite {
  11.         private var _tf:TextField;
  12.        
  13.         public function AirTest() {
  14.             _tf = new TextField();
  15.             _tf.text = "My AIR2 App!";
  16.            
  17.             _tf.autoSize = TextFieldAutoSize.CENTER;   
  18.             _tf.x = (stage.stageWidth - _tf.width) / 2;
  19.             _tf.y = (stage.stageHeight - _tf.height) / 2;   
  20.  
  21.             addChild(_tf);
  22.         }
  23.     }
  24. }

So this is it. This is the file we're going to compile to our AIR-Application!

The Application Descriptor:

To publish an .air file we always need writing a description file for our application first - by the way it's common this file is called the Application Descriptor. It always looks pretty similar as it's an XML file with descriptive nodes. Each node specifies an application's property like name, id, the initial window's size, whether it's transparent or not, the taskbar icons and all the like. Every AIR application needs them and therefore you can work with a template and adjust the values. By standard you name this .xml file the same as your project and add an -app to it. So in my case it's named AirTest-app.xml.

Create a new XML file on your project's root directory, name it appropriately like told above, paste in the following code and edit the properties as you want. Don't forget to change the content-property!

XML:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2.  
  3. <application xmlns="http://ns.adobe.com/air/application/2.0">
  4.     <id>AIR2-Test</id>
  5.     <version>2.0</version>
  6.     <filename>AIR2 Testapp</filename>
  7.     <name>AIR2 Testapp</name>
  8.     <description>
  9.         <text xml:lang="en">www.beautifycode.com</text>
  10.     </description>
  11.     <copyright>Copyright (c) 2010 Marvin Blase</copyright>
  12.     <initialWindow>
  13.         <title>Beautify Code AIR2 Testapp</title>
  14.         <content>AirTest.swf</content>
  15.         <transparent>false</transparent>
  16.         <visible>true</visible>
  17.         <minimizable>true</minimizable>
  18.         <maximizable>false</maximizable>
  19.         <resizable>false</resizable>
  20.         <width>640</width>
  21.         <height>480</height>
  22.         <minSize>320 240</minSize>
  23.         <maxSize>1280 960</maxSize>
  24.     </initialWindow>
  25.     <installFolder>Beautify Code/AIR2 Testapp</installFolder>
  26.     <programMenuFolder>Beautify Code</programMenuFolder>
  27.     <icon>
  28.         <image16x16>icons/AIRApp_16.png</image16x16>
  29.         <image32x32>icons/AIRApp_32.png</image32x32>
  30.         <image48x48>icons/AIRApp_48.png</image48x48>
  31.         <image128x128>icons/AIRApp_128.png</image128x128>
  32.     </icon>
  33.     <customUpdateUI>true</customUpdateUI>
  34.     <allowBrowserInvocation>false</allowBrowserInvocation>
  35.     <fileTypes>
  36.         <fileType>
  37.             <name>adobe.VideoFile</name>
  38.             <extension>avf</extension>
  39.             <description>Adobe Video File</description>
  40.             <contentType>application/vnd.adobe.video-file</contentType>
  41.             <icon>
  42.                 <image16x16>icons/AIRApp_16.png</image16x16>
  43.                 <image32x32>icons/AIRApp_32.png</image32x32>
  44.                 <image48x48>icons/AIRApp_48.png</image48x48>
  45.                 <image128x128>icons/AIRApp_128.png</image128x128>
  46.             </icon>
  47.         </fileType>
  48.     </fileTypes>
  49. </application>

See AirTest-app.xml

A powerful ANT-Build:

For the purpose to combine the mentioned tasks (publish / create certificate / package) we need a lot of compiling commands to be executed after another. The easiest way to do so is working with an ANT Build as it uses JAVA to run mxmlc and adt, which is both necessary for compiling an AIR file. Using ANT is really simple in FDT as you only have to open the ANT view (either you have once minimized it, then it's an icon at the most left bar in FDT4 or you have closed it - in that case you can go to Window > Show View > ANT and reposition it to where you like to).

Now we need the ANT file which contains all this magic, don't we?

Download buildAIR2_ant.zip and extract it to your project's root directory. This file is most essential in this project so I will talk about it a bit in detail. But first of all let's simply drag & drop the buildAIR2.xml into the ANT window:

Drag and drop the ANT fileThe ANT Build









As you can see there are now different tasks you can execute by just doubleclick on them. But before doing we have a bit to set it up regarding to your project. Open the buildAIR2.xml in FDT so we can edit the file itself. Don't be scared - although the file is pretty long you do not have to change more than one or two lines. Let's have a look at them (18-29) and on what to change there:

XML:
  1. <!-- Path to Flex 4.1 SDK -->
  2. <property name="sdk_dir" value="/Applications/FDTEnterprise/plugins/flex_sdk_4.1.0.16076" />
  3. <property name="mxmlc" value="${sdk_dir}/lib/mxmlc.jar" />
  4. <property name="adl" value="${sdk_dir}/bin/adl.exe" />
  5. <property name="adt" value="${sdk_dir}/lib/adt.jar" />
  6.  
  7. <!-- Project properties -->
  8. <property name="app_name" value="AirTest" />
  9. <property name="app_root_dir" value="." />
  10. <property name="app_type" value="as" />
  11. <property name="assets_dir_name" value="assets" />

Most important is the path to your Flex SDK. Please make double-sure it is correct. Then very essential to change as well is your Application Name - as this has exactly to be the same as your Main-Class! Last but not least you obviously have to change "adl.exe" to "adl" as a Mac user. The following lines depend on the certificate. We will have a look on that later - for now the set values are okay. Now let's see some action and see what each task does in real.

1. Cleanup Directories

This is the default task. It removes old compiles / publishes / settings from previous packagings. So at the moment it simply does nothing.

2. Build New Directories

This task is always called before any compile (either SWF or AIR) saves the file. Because otherwise JAVA would just throw an error when trying to access a non-existing directory. When doubleclicking it the following pops out of your console:

JAVA:
  1. 2. Build New Directories:
  2. [mkdir] Created dir: /debug
  3. [mkdir] Created dir: /publish
  4. [mkdir] Created dir: /build

And when refreshing your filebrowser you notice these new three folders. Isn't that cool? I could doubleclick this task the whole day over and over again, but well.. Maybe after finishing this article. However, I think the foldernames are pretty self-explaining.

3. Compile SWF

By executing this task you finally create a SWF based on your AS3 Class file. It will be stored in the /publish directory. If you have set up everything correctly this is the first step where you can see if everything works so far. The best indication for that is this console output:

JAVA:
  1. BUILD SUCCESSFUL

Refresh your filebrowser and check if there is a new .swf file in your /publish folder.

4. Compile SWF (Debug)

Same thing but published with debug-capability to /debug directory.

5. Test Application

Yea - this is the first time AIR comes into play. When doubleclicking this task a debuggable SWF file is compiled and opened with the Adobe AIR Launcher. As we all know it directly works and any traces are executed and shown in the FDT console. Cool, he?

6. Package Application

Now here comes all the important stuff together. A non-debuggable SWF file will be compiled and then the ADT - AIR Development Tool - is launched with many, many options. These options are equal to the values you've declared in your Application Descriptor and the ANT build's certificate settings. When starting it without having a certificate created first it will throw errors like:

JAVA:
  1. [java] could not load keystore file (password may be incorrect)

7. Create New Certificate

This task does what it's called like. The options (like password / encryption / name / where to save / ...) can be changed in the ANT Build itself (see above). The certificate file will then be stored in the assets/settings directory.

See buildAIR2.xml

Digitally Signing / Certificates:

Using a certificate is required when publishing an AIR application as it contains every identity's, owner's and location's information. In our case setting this up doesn't take too long. In our buildAIR2.xml there are two paragraphs for these settings. One for using an existing certificate by authorizing with it's name & password and one for writing a new one, with a name, password and the required data. The ANT Build is appropriately commented on this:

XML:
  1. <!-- Certificate properties -->
  2. <property name="certificate_name" value="exampleCert" />
  3. <property name="certificate_pw" value="examplePW" />
  4.  
  5. <!-- Required for creating a new Certificate -->
  6. <property name="cert_name" value="exampleCert" />
  7. <property name="password" value="examplePW" />
  8.  
  9. <property name="org_name" value="exampleOrg" />
  10. <property name="org_unit" value="exampleUnit" />
  11. <property name="country" value="DE" />
  12. <property name="key_type" value="2048-RSA" />
  13. <property name="cert_loc" location="${app_root_dir}/${assets_dir_name}/settings" />

As you can see the AIR file even works with any information. After we've created a new one with the 7th build task the same certificate is used (see name and password) to be packaged with the AIR file. Make sure to create a new certificate for every AIR application.

Publisher unknown / Application unverified

If you're just getting started with Adobe AIR and don't want to shell out money, you can always sign your application with an untrusted certificate to allow the AIR runtime to install your application as UNVERIFIED publisher to get you through your testing cycle.

That means if you're going to be a verified publisher you have to buy an AIR development certificate (priced around 300$ a year). So for everyone interested in trustfully signing his applications, here's a comprehensive article on How to get a certificate? by Adobe.

Most Common Errors:

While packaging:

JAVA:
  1. Invalid namespace http://ns.adobe.com/air/application/2.0

Solution: This is by far the most happening error. Okay, there are two things you have to check. First: Did you really link the new SDK in your ANT build? Second: Is this SDK Flex 4.1?

JAVA:
  1. Unable to access jarfile ... mxmlc.jar

Solution: Your SDK path is not correct.


While creating a certificate:

JAVA:
  1. [java] unable to create output file
  2. [java] Java Result: 11

Solution: Create a settings folder in your assets directory.


While starting the .air file:

JAVA:
  1. Installer file is damaged!

Solution: Okay, I've heared of that and even seen that once. What I did then was changing the JRE and package it again.

Open the External Tool ConfigChange the JRE









Summary & Sample-Project:

Okay, we're done. After executing the 7th and then the 6th task there should appear the following output in your console:

JAVA:
  1. 7. Create New Certificate:
  2.     BUILD SUCCESSFUL
  3.     Total time: 2 second
  4.  
  5. 2. Build New Directories:
  6.     [mkdir] Created dir: .../AirTest/debug
  7.     [mkdir] Created dir: .../AirTest/publish
  8.     [mkdir] Created dir: .../AirTest/build
  9.  
  10. 3. Compile SWF:
  11.     [java] Configurationfile .../frameworks/air-config.xml is loading
  12.     [java] .../AirTest/build/AirTest.swf (731 Byte)
  13.  
  14. 6. Package Application
  15.     BUILD SUCCESSFUL
  16.     Total time: 19 seconds

The resultAn .air file is stored in the publish/ directory. Doubleclick it and an installer pops up - there we go :) Hopefully I could lead you to the same result I've got. If not feel free to ask any questions. You can take my project-files if you like to but keep in mind to change the mentioned values.

Download AirTest_project.zip




Chek the follow-up articles as well:
Use SWC files within your ANT Build (known as Linked Resource)
Use source folders within your ANT Build (known as Linked Resource)
Chromeless Designs - A Designer's Look

29 Responses to “AIR2 and FDT4 (M4) – A detailed Walkthrough with ANT”

  1. [...] This post was mentioned on Twitter by Bruno Fonzi, Bruno Fonzi, Bruno Fonzi, WE ♥ FDT, Marvin Blase and others. Marvin Blase said: just posted the probably longest article on my blog yet: #air2 #air #fdt4 walkthrough: http://bit.ly/bzSpva [...]

  2. Matthew Jalie says:

    This article is definetly worth reading, wow! I've followed the steps and can finally compile AirApplications in my beloved FDT. Thanks, thanks, thanks Marvin!

  3. Alexander Stefas says:

    Hi,

    thanks for this post. It came exactly at the right time...

    I am wondering how i can add linked ressources to this workflow. I am getting the errors as described in the previous post.

    Regards Alex

  4. Marvin Blase says:

    did you check the latest article on this blog? it´s exactly about that :)

  5. Alexander Stefas says:

    Hi Marvin,

    I know, but a linked ressource is something different than a .swc, isn't it?

    Let's say you have a project with 10 linked ressources, all added to the FDT
    Build Path and containing their own src folders. How can I add these into my ANT
    workflow without copying their src folders to the projects src folder?
    The previous post just points to an alternative src folder inside the actual project/${assets_dir}/lib/ where
    you put a compiled .swc, here some assets. But you could have added this .swc to yout build path in the first place, or am I just a bit confused and mixing things up due to the fact its friday ;-)

    Regards Alex

  6. Marvin Blase says:

    Ah, you mean Linked Libraries. To be honest I haven't come to this point yet :) But as it will bother me pretty soon I'm going to find out and post then. I'm pretty sure there is a way.

  7. Alexander Stefas says:

    ok... linked libraries is the right term ;-)

    I guess as a workaround one can write another ANT task, which previous to the actual compilation process
    copies all src folders of all linked libraries to the src folder. But somehow i thought that there has to be a better way, because you will have to adjust this ANT task for every project.

    i am curious for a solution ;-)

  8. Alexander Stefas says:

    ... and, what i forgot, there might be a problem with namespaces and corresponding folders as you copy several linked libraries with com.* to your projects src folder...

    maybe the additional ANT task is not a good idea at all...

  9. [...] Hi, i have seen many tutorials with ANT to create a AIR App file like => MyApp.air <= Like this tutorial => Marvin Blase AIR 2 and FDT 4 [...]

  10. [...] impressed with the output of FDT based posts by the community in particular Marvin Blase’s Air 2 / FDT 4 walkthrough and looking over what I needed to learn to start to build a multi-screen air application I stumbled [...]

  11. Steven Sacks says:

    This tutorial is incomplete. External swcs and linked swcs aren't accounted for, and your solution doesn't include the applicationupdater.swc, which numerous AIR projects use.

    Your solution is only for the most simple test example of a non-real world application. It does not yet meet the minimum requirements of real world AIR application packaging because it leaves out too many important things.

    I'm hoping you can address these missing items. Until then, I'm going go stick with FB's one click packaging. Yes, it's somewhat of a pain to switch from FDT to FB to build, but at least it works.

  12. Marvin Blase says:

    if you start swimming you won't directly go for olympia, will you? this guide is meant as the first steps, from sketch to a published file. everything that comes up - like using external sources, updating, etc. are definetly required when going for a realworld application. but up to this point you've got an .air file, you've got a step-by-step setup done, you know what's happening. i actually cover some of the upcoming topics in more recent posts, so this tutorial isn't incomplete - it's a beginning. and the tale is not over yet.

  13. forex says:

    Hi admin. I was just looking for for some informations on this topic in order to write an post in my new blog. Can I post a link to this post on my blog ? Thanks. Pedro

  14. alberto says:

    Hi Marvin,
    i found your post deeply useful. thanks!
    one thing though I couldn't sort out, everything works fine but when i go for a Test Application in ant I can't get any traces from the console panel.
    Any clue on what might be wrong? I'm using the same SDK and FDT4. Thanks!

  15. Paul says:

    Hey,

    Great, but am having some problems ..
    Here is the output:

    3. Compile SWF:
    [java] Loading configuration file /Applications/FDT4/FDT/plugins/com.powerflasher.fdt.shippedFlexSDK4_4.0.0.14159_1000/flex/frameworks/air-config.xml
    [java] Adobe Flex Compiler (mxmlc)
    [java] Version 4.0.0 build 14159
    [java] Copyright (c) 2004-2009 Adobe Systems, Inc. All rights reserved.
    [java] Error: unable to open './src/AirTest.as'
    [java] Use 'mxmlc -help' for information about using the command line.

    BUILD FAILED
    /Users/admin/Documents/workspace/AirDemoProject/bin/buildAIR2.xml:76: Java returned: 1

    Now I have x100 checked that ther eis AirTest.as in src .. I can see it, I know its there .. the debug works ahhh .. what can I be doing wrong ???

    Best
    Paul

  16. Marvin Blase says:

    Hi Paul,
    "Error 1" is mostly caused because of two problems.. the first is a memory leak which makes it unable to R/W into the RAM and out. Honestly I've got no idea how to fix this as this is JAVA compile stuff I'm not too familiar with. Secondly this error can occur because of permission issues.

    Line 76 should be something with creating directories or the like, eh? Check if the directory you're using is accessible to you and e.g. try logging in as root to do so.

  17. Paul says:

    Ahhhh .. I got it working .. finally :)
    It came down to not having things in the right place...
    Could I suggest that you add a image of the folder stucture .. for example:
    http://img10.imageshack.us/i/screenshot20110110at348.png/

    Best
    Paul

  18. alberto says:

    Hi Marvin,
    I'm still stuck with the debugging issue. I've added this task to your ant file:

    That, launched before the testing task, #5, worked well, I could finally get traces from AS3 again!
    Suddenly though, it worked for few hours only. Now I get this error message.
    Even though I haven't change the ANT file anymore:
    BUILD FAILED
    /Users/alberto/Documents/FDT/workspace_4/Isola03/buildID03.xml:160: Problem: failed to create task or type fdt.startDebugger
    Cause: The name is undefined.
    Action: Check the spelling.
    Action: Check that any custom tasks/types have been declared.
    Action: Check that any / declarations have taken place.
    In FDT I've got correct value when investigating for "${app_name}".
    Could anyone please provide little bit more details about debugging with this workflow, wich I think has a good set-up? Cheers.
    alberto

  19. Marvin Blase says:

    Hey Alberto,
    could you upload your .xml file somewhere? No way to determine the error without the source.

    However it sounds a bit like an FDT issue. May it be you're using the Pure version?

  20. alberto says:

    Thanks Marvin.
    Here's a copy of the project based on your giudelines, I didn't include the asset swc since I havent used any of them in the code yet. I hope you can point me in some direction..I really don't want to use FlashBuilder...
    Here's the link to the source zip:

    http://3ulls.com/__fdt/sample_fdt_air_prj.zip

    Also I'm on FDT 4.1, MAX version.

    Thanks again, cheers!
    alberto

  21. [...] then create a new Flex project. For deploying to your phone I’m going with antpile or follow this tutorial.Links:Flex 4.5 Hero SDK with flash developPackage an air file with antAndroid Air [...]

  22. Paul says:

    I was wondering how you would "include" other files .. like a .html file ?

    Paul

  23. [...] Marvin Blase‘s blog post über Air 2 / FDT 4 walkthrough gibt es hierbei eine solches Ant-Skript, um Air-Applikationen zu kompilieren, an dem ich mich [...]

  24. [...] AIR2 and FDT4 (M4) – A detailed Walkthrough with ANT [...]

  25. I think that is one of the so much important info for me. And i am satisfied reading your article. However wanna commentary on some basic issues, The site taste is ideal, the articles is actually nice : D. Excellent job, cheers

  26. Mac Adobe says:

    Woah this blog is excellent i like studying your posts. Keep up the great work! You realize, lots of individuals are hunting round for this information, you can aid them greatly.

  27. Hello there, I am new to running a blog and internet
    sites in general and was wanting to know how you got
    the "www" included in your domain name? I see your domain, "http://www.beautifycode.com/publish-package-an-air-file-with-fdt4" has the www and my
    web address looks like, "http://mydomain.com".
    Do you know the way I can change this? I'm using WordPress. Warm regards

  28. If you would like to take a good deal from this article then you have to apply these methods to your won weblog.

Leave a Reply

Powered by WordPress | Free T-Mobile Phones for Sale | Thanks to Palm Pre Blog, Video Game Music and Get Six Pack Abs