This is part 4 of our Windows ANE tutorial which walks you through making an Adobe AIR Native Extension for Windows.
At the end of this part you will have:
An Adobe AIR Native Extension (ANE) ready to be used on Windows.
Wait, have you done this first?
- Part 1: The native DLL project, 8-10 minutes
- Part 2: The Native DLL code, 10-15 minutes
- Part 3: Set up the AIR Library – 8-10 minutes
Option 1: Package the ANE by hand
Ahh, even my keyboard is shaking with distaste as I’m typing this… I have a reputation for passionately hating build processes that require more than a single click. Option 1 has… well you count how many clicks, drags and head-scratches it has.
Realistically, though, if this is your first ANE or first one for Windows, packaging it by hand is a great option. It shows you what goes in and will give you ideas for how to automate the process. Or will help you understand the automatic build scripts I will send you. If you ask me nicely in the comments below, that is.
Without further ado, let us roll up our sleeves and do some packaging…
1. Extract library.swf
When you built your AIR library in the previous step you probably got a SWC file in your project’s bin folder, called DiaDrawWindowsANETutorialAIRLib.swc. In there somewhere library.swf hides. Here is how to get to it:
Make a copy of DiaDrawWindowsANETutorialAIRLib.swc and rename it to DiaDrawWindowsANETutorialAIRLib.zip and unzip it. This should produce two files: catalog.xml and library.swf. Discard catalog.xml and the renamed .zip file and keep library.swf.
2. Collect all ingredients
For Windows these will be:
- library.swf, which you just extracted
- DiaDrawWindowsANETutorialAIRLib.swc (you didn’t get rid of it, did you?)
- DiaDrawWindowsANETutorialAIRLib-extension.xml – the extension descriptor file which you created in Part 3: Set up the AIR Library
- DiaDrawWindowsANETutorialDLL.dll – the native library you built in Part 2: The Native DLL code
3. Go on the command line
Copy all of the ingredients listed above into one folder and navigate to it from Windows Command Prompt.
Run the following command:
adt.bat -package -target ane DiaDrawWindowsANETutorial.ane DiaDrawWindowsANETutorialAIRLib-extension.xml -swc DiaDrawWindowsANETutorialAIRLib.swc -platform Windows-x86 library.swf DiaDrawWindowsANETutorialDLL.dll
What this does is run the AIR SDK adt utility and instruct it to package the files you have collected into an ANE product (target) for Windows.
Note that if adt.bat is not on your Windows search path, you can provide the full path to it. Adt.bat normally lives in the bin folder of your AIR SDK, for example: C:/Program Files (x86)/Adobe/Adobe Flash Builder 4.6/sdks/4.6.0/bin/adt.bat. Don’t forget to put the path in quotes, as Command Prompt doesn’t like spaces in paths.
If packaging was successful you should end up with DiaDrawWindowsANETutorial.ane in the same folder where you ran the packaging command.
Option 2: Automate your ANE packaging
An automatic build? Now we’re talking. All that shenanigans of gathering files, renaming, unzipping, running commands by hand takes time. And if you have to do that for every single change you do in your code and want to debug it (you do debug, yes?), what are the chances of you doing that often versus coding away blind?
So. Check out these two tutorials:
You will probably notice these walk you through creating build scripts for iOS. Well, dedicated reader, here is a little homework for you: the same principles apply for making a build script for Windows, Android or Mac OS.
If you are in a hurry and want the ready-made scripts for Windows, shout in the comment section below. A recommended opening line is “Automated builds rock because…” 😀
- Part 5: Testing the ANE – 12-15 minutes
- See the table of contents for the tutorial, in case you want to jump back or ahead.