Hello dear habrachiteli. My story as you can see from the title of the theme will go about the basis and features of creating an adobe native extension (hereinafter ANE) for Adobe AIR, in my case I will write extensions in java, to extend the functionality of AIR, on the Android platform. And so with your permission begin.
Introduction
What is ANE? This tool, which appeared with Adobe AIR 3.0 and higher, allows you to extract and execute pieces of native code from the AIR environment, conditionally we can run any native code. The extension looks like a compiled library file with the extension .ane.
What you need to work
To get started, we need:
1. As IDE Eclipse.
2. Flash Builder 4.6 plugin
3. ADT plugin.
4. Adobe AIR SDK.
')
How to start all this and write the code I will not explain because this topic goes beyond the limits of this article, by default the article assumes that you have all these subtleties ..
About programming extensions to JAVA.
First, let's create an Android project, having previously marked it as a library and most importantly, let's not forget the name of the package, this name will be described in the extension description file a little later.
The main extension class essentially implements the FREExtension interface ... this interface, like many other classes, comes from a separate library from adobe, where do we find this library? It can be found inside the AIR SDK, at lib / android /. Libraries are called FlashRuntimeExtensions with jar and so extensions. We write on java according to this we need a jar, take our library and connect it to our project. And so let's create the main class of our extension, it should have the following structure:
@Override public FREContext createContext(String arg0) { return null; } @Override public void initialize() { } @Override public void dispose() { }
As we can see, the structure of our class is pretty simple, three mandatory methods, with the dispose and initialize methods, I think, and so everything is clearly invoked during initialization and destruction of the extension. The createContext method is interesting. Conventionally, an extension has its own context that will describe the functionality of our extension, as we understand the class of our future context should extend the FREContext class. Let's create a class of our context, the class should have the following structure:
@Override public Map<String, FREFunction> getFunctions() { return null; } @Override public void dispose() { }
Here you should pay attention to the getFunctions () method. In essence, this method returns the maps, the key of which is the name of the method that we use when calling from as3, and the value is the function that implements the FREFunction interface, in which all the functionality of the called method of our extension is enclosed. The function class should have the following structure:
@Override public FREObject call(FREContext context, FREObject[] args) { return null; }
As you can see here we have only one mandatory method. Access to the activity of the current application can be obtained through an instance of the FREContext class, which we receive as a parameter in our function, using the completely logical getActivity () method and having a native Androdovsk activity one can do with it everything your heart desires. Also, an instance of the FREContext class has the dispatchStatusEventAsync method, which allows you to make a callback in as3, the results of which can be heard by using the StatusEvent.STATUS event. The second parameter of the method is an array of FREObject classes, these are all parameters that will be passed to our context from as3. An instance of the FREObject class has a set of methods for converting to the corresponding data type.
This concludes the java part and proceeds to as3.
About programming extensions on AS3.
To create a library, let's create a Flex library project, while not forgetting to import the AIR classes, and the class package must be identical to the one in java.
The main class on as3 can extend anything, just create a class and in it create an instance of the ExtensionContext class, it is created as follows:
var extContext:ExtensionContext = ExtensionContext.createExtensionContext(" ", " ");
now we have an instance of the context of our extension, you can listen to it as we wrote above, as follows
extContext.addEventListener(StatusEvent.STATUS, onStatus);
You can also call the method we described in the context in java as follows:
extContext.call(" ", ..." )
Everything is quite simple, now let's try to collect our ane.
Build ane.
And so, after all our labors, we should have swc from our flex project and jar from our android project.
Let's create a separate directory, and inside it we will organize the following hierarchy:

Inside the android folder should be our jar library, in cases if you are developing ane for ios or something else like that, the directory should correspond to its name. Another important one before compiling is to pull out the library.swf file from the swc library (open your swc file with help, for example, the winrar archiver) and drop it into each directory. Approximately the android directory will have two files and look like this:

And the default directory will contain only the library.swf file.
Now we need to describe our extension in the descriptor of this file extension.xml, in our case it will look something like this:
<extension xmlns="http://ns.adobe.com/air/extension/3.1"> <id> </id> <versionNumber> </versionNumber> <platforms> <platform name="Android-ARM"> <applicationDeployment> <nativeLibrary>test.jar</nativeLibrary> <initializer> java </initializer> </applicationDeployment> </platform> <platform name="default"> <applicationDeployment/> </platform> </platforms> </extension>
Well, now everything is almost ready for us. It’s just left to build our library, for this we execute from the console (do not forget to set the path to the Adobe AIR binaries in the environment variables):
adt -package -target ane extension.ane extension.xml -swc test.swc -platform Android-ARM -C android . -platform default -C default .
Where extension.ane is our ane to be created, and test.swc is our flex library. You will end up with an ane file that you can use.
On this, I guess I'll finish with the basics. Thank you for your time and patience, and if anyone is interested, wait for the continuation.