Need Flex Migration Help?
- Adobe ends Flash player support in 2020
- Flex apps will no longer function
- We can help migrate your app
This is the last step of the native extension build process. Did you miss something or are you late to the party? Jump back to step 1.
Now that all of the supporting projects have been built and compiled, it’s time to put it all together. For native extensions, that means building a .ane file.
Building the ANE
1) Put all of the files into a folder together. The structure should look like:
build directory -extension.xml -SWC for main ActionScript library android -androidLib.jar -library.swf (main ActionScript library) ios -iOSLib.a -library.swf (main ActionScript library) -platformoptions.xml (if required) default -library.swf (default library)
2) Run the following command:
adt –package –storetype pkcs12 –keystore cert.p12 –storepass XXXX –target ane Name.ane extension.xml –swc Name.swc –platform iPhone-ARM –C iOS . –platformoptions ios/platformoptions.xml –platform Android-ARM –C android . –platform default –C default .
Exclude any platforms that you aren’t supporting.
The –C directory . indicates that all of the files in directory should be included in the ANE. The command –C directory library.swf would make only the file directory/library.swf be included in the ANE.
Signing the ANE is optional, but Flash Builder will have a warning when using unsigned native extensions. You can use any p12 to sign a native extension, including a p12 built from Flash Builder during the release build process, so it’s easy to sign the ANE.
3) Include the ANE in the application.
Go to the properties of your project. Navigate to “Flex Build Path” and go to the “Native Extensions” tab. Click “Add ANE…” and find the ANE you built.
At some point, either during this step or one of the following steps, Flash Builder should indicate that the package of the ANE must be included in the app descriptor file and that Flash Builder will automatically include it. Say yes to this prompt.
Now that the ANE has been added, you must toggle it on for each platform you are supporting. Expand the “Flex Build Packaging” item.
If supporting iOS, click on the “Apple iOS” item. Go to the “Native Extensions” tab. Be sure that the checkbox in the “Package” column next to your ANE is checked. Also be sure to reference the iOS SDK (as mentioned previously) in the “Apple iOS SDK” input. Click “Apply”.
If supporting Android, click on the “Google Android” item. Go to the “Native Extensions” tab. Be sure that the checkbox in the “Package” column next to your ANE is checked. Click “Apply”.
Now click OK and clean your project. You’re ready to implement the native extension now!
Note: If you make any changes that require you to rebuild the ANE, I suggest removing the ANE from the “Flex Build Path -> Native Extensions” tab and redo the steps in item #3 (this one!) to re-add the ANE. I’ve has some caching issues where an old version of the ANE is used if I didn’t totally remove it and start the add process over from scratch.
Note: If you make changes to any of the libraries, be sure to update the files in the build directory! It’s especially easy to overlooking extracting the library.swf file from the main ActionScript library’s swc file. Also be sure to place this library.swf file in both the iOS and Android directories.
Note: It’s very possible to automate this process via ANT. I don’t cover it here, but many other examples use ANT to perform the entire packaging process. You can even extract the library.swf from the swc files using ANT.
Creating a native extension has a lot of steps and it’s easy to overlook some of the finer details that are required to get the ANE working. There are a lot of great examples out there so check them out and get an even better understanding of the power native extensions give you.