Using ANE (Air Native Extensions) in Haxe

The games we build, are written in Haxe, published as SWFs and packaged with Adobe AIR. I don’t want to kick off a discussion, why we use Haxe and don’t use NME, but that is a story for another post ;) So one challenge is: How do we integrate stuff like Game Center on iOS etc.? When you work with Flash and AIR this is a no brainer. Just google for it and you will find thousands of solutions… But try to google Haxe + ANE… “How to build ANE with Haxe” err no, not really. “How to use NME Native Extensions” again, no, we do not use NME. And so on… Maybe i’m too stupid to use Google, but I did not find a single bit of useful information.

OK, but this must be working somehow. And for my surprise it was dead easy. For my simple test I used the gyroscope ANE provided by Adobe. Here we go:

Extracting all we need from the ANE
-Unpack the “” and find the SWC (in this case in the “Binaries” folder)
-Copy the SWC somewhere and rename it to .zip
-Unpack the ZIP
-Now you should have a new folder names “Gyroscope” with two files “catalog.xml” and “library.swf”. The latter is what you need!

The easy task: Build your Haxe app
All you have to do before starting, edit your .hxml file and add:

When linking the “library.swf” from the extension, you will now be able to use all the stuff from the original SWC. Code completion works for me in Sublime on Mac! You can now write the exact same code as in Adobe’s example:

Build the AIR App
Ok, now we have a SWF, but we need some .apk or .ipa for mobile. I will show how to make a Android version, but iOS is nearly the same (Providing an iOS example is useless unless you have all the certificates you need from apple…). To compile you project as AIR App you will need the following things:
-AIR SDK (haxelib install air3)
-SWF File from previous step
-.ane file (in the “Binaries” folder of the “”)
-An AIR descriptor file

In the descriptor you must link the extension:

No matter if you target iOS or Android, the three lines are the same for both systems.
To build the App i recommend to use ANT. There are three files in the “ant” folder which i don’t want to explain in detail. There are a million tuts for ANT out there, no need to write another one ;) The only important line is this argument you pass to the ADT compiler:

Without telling the compiler where to find the .ane compilation will fail.

That’s it. All files are created. Let’s start compiling (go to the “ant” directory first!):

After a few seconds, compilation should be complete and you can find the “ANETest.apk” in the “bin” folder. Load it to your mobile device and test if everything works.

You can download the whole sample project here.

Tagged with: ,
Posted in Programming, Sourcecode

Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>