Adobe AIR Native Extensions for iOS, Learnings
January 22nd, 2012 | Posted by in Actionscript | iPhone | TalkIn my current client project, we’re developing an AIR application targeted for iOS (Android will follow) and we wanted to make use of some iOS SDK features, so I had to write my first NativeExtension. Developing the Objective C part is pretty straight forward (If you know C++ and Objective C) and so is the Actionscript part. There are some good examples and tutorials on the Adobe site about all kind of extensions.
The hard part was to get this thing to work. So I just wanted to share my settings here. This might become useful, if you’re starting to develop your first ANE. I had strange crashes when I packaged the app with my ANE and I couldn’t figure out what was wrong. The app just crashed everytime I launched it on the device. The crashlog wasn’t very helpful. After quite a search, I found out, that I didn’t set an apparently important compiler flag for the LLVM compiler in my XCode project. So, be sure to set:
Enable Linking With Shared Libraries: No
And if you want to get rid of the warnings:
Warnings: Missing Function Prototypes: No
The second part was packaging the ANE correctly. The working command for my case is:
adt -package -target ane MyExtension.ane extension.xml -swc MyExtension.swc -platform iPhone-ARM library.swf libMyNativeExtensionIOS.a
The annoying thing about packaging the ANE is, that after you have built your swc, you have to extract the library.swf out of it (By renaming it to .zip and extracting the swf). So you need both, the swc AND the swf. I didn’t write an ANT task to do automate the process until now and I don’t know the reason for this strange step, since the ADT compiler has everything it needs within the swc. Only Adobe knows ;)
Obviously you can not test on the device everytime, because the deployment process to iOS is more or less manual and just takes too long at the moment. I found out, that I could link the ANE as a regular library (SWC) in my Flash Builder project and launch the app on my desktop machine. When the native extension tries to create the context on the desktop machine, it fails and returns null, because it was just built for the iOS platform:
context = ExtensionContext.createExtensionContext(EXTENSION_ID, null);
So I could implement a fallback for the extention when running on the desktop that mocked the behaviour in AS3. To package the application for iOS, I wrote a small ANT task. This way we can easily test on the device and have a fallback, when testing 0n the desktop without writing desktop extensions as well.
So, maybe someone will find this useful…
You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.




Hello Lars,
Great findings. I hope that you read them somewhere, otherwise you are the next guy who has found them the hard way – trying and failing. I have the same struggles a while ago. Again for a project which has to use a few ANEs. :)
Best regards,
Emil
The CS5.5 method was a kerfuffle… but in CS6, it seems to have been streamlined to a certain degree…
CS6 and ANE files: http://www.adobe.com/devnet/air/articles/using-ane-in-flash.html