To use a native extension in an AIR application, you have these three tasks to do:
- Declare the extension in your application descriptor file.
- Include the ANE file in your application’s library path.
- Package the application.
This post is about Step 2 with regard to Flash Builder 4.5.1 projects.
Native extensions are packaged in ANE files. To compile an AIR application that uses a native extension, include the ANE file in the Flash Builder project’s build path.
In Flash Builder 4.5.1, do the following steps:
- Change the filename extension of the ANE file from .ane to .swc.
- Select Project > Properties on your Flash Builder project.
- Select the Flex Build Path in the Properties dialog box.
- In the Library Path tab, select Add SWC….
- Browse to the SWC file and select Open.
- Select OK in the Add SWC… dialog box. The ANE file now appears in the Library Path tab in the Properties dialog box.
- Expand the SWC file entry. Double-click Link Type to open the Library Path Item Options dialog box.
- In the Library Path Item Options dialog box, change the Link Type to External.
Now you can compile your application using, for example, Project > Build Project.
The part about changing the ANE file’s file extension from .ane to .swc is not strictly necessary. In step 4 above, when you browse to find the file, in the “Choose a SWC file” dialog box, you can change the setting of the Files Of Type drop-down field. It is set by default to *.swc. Change it to *.*.
Now you can choose the ANE file. Then, continue with step 5 above.
However, when you build your Flash Builder 4.5.1 project with an ANE file rather than a SWC file, you get compiler warnings. The first warning is on the import statement for the extension class, saying that the extension could not be found. Successive warnings occur when you use the extension’s classes.
But interestingly, the application still builds and runs successfully.
Note: Adobe recommends using the next version of Flash Builder for developing native extensions for Adobe AIR. Sign up now to get access to the prerelease of Flash Builder 4.6.
For more information about using a native extension in your AIR application, see Using native extensions in AIR applications.
Detailed documentation about creating extensions is at Developing native extensions for Adobe AIR.