What an AIR native extension actually does
AIR gives you a large set of built-in features, but some device capabilities are not exposed. A native extension (ANE) is a package that lets your ActionScript code call code written for the platform itself, such as Java or Kotlin on Android and Objective-C or Swift on iOS.
The three parts
- The ActionScript library. A normal class API that your app imports. This is what you write against.
- The native code. One implementation per platform, compiled and bundled into the package.
- The descriptor. An XML file that declares which platforms the extension supports and where each implementation lives.
How calls travel
Your app creates an extension context and calls a method by name. The native side runs, then reports back either with a return value or by dispatching a status event. That means asynchronous work such as sensor readings comes back as events you listen for.
var ctx:ExtensionContext = ExtensionContext.createExtensionContext("com.example.sensor", "");
ctx.addEventListener(StatusEvent.STATUS, onStatus);
ctx.call("start");
function onStatus(e:StatusEvent):void {
trace(e.code, e.level);
}
Using one in your app
- Add the extension package to your project's build path.
- List its identifier in the
extensionssection of your application descriptor. - Package with the extension directory set, once per target platform.
- Test on real devices. The desktop simulator usually cannot run the native part.