I thought I better post this while it’s fresh on my mind.
Yesterday, I decided to make my 3rd attempt at building an ActionScript Native Extension for Android, and I found this great tutorial here: http://www.adobe.com/devnet/air/articles/developing-native-extensions-air.html
While that tutorial is great, it covers everything up to the packaging part, and then the instructions get very unclear and confusing. So, I’d like to pick it up at that point…
From here on out, I’m assuming that you have:
- Created your vibration.swc File
- Created your vibration.jar
- Created your extensions.xml file
At this point you have all the pieces you need, but the packaging step is a bit confusing…
Before packaging the ANE, you first want to setup a build directory in a certain way:
- Copy vibration.swc into the build folder
- Copy extension.xml into the build folder
- Create a “default” folder, and a folder for each platform you wish to support, ie “Android-ARM”
- Crack open the SWC in WinZip, and drag the library.swf file, into each of your subfolders.
- Paste the native code into each platform directory, in this case the only platform is Android, so copy “vibration.jar” into “Android-ARM”
If you have something like that, you’re good to go on to the next step.
I had a couple issues with the build script posted in the tutorial. Specifically I hit these gotcha’s:
- The path to native_dir must NOT be wrapped in quotes, or you’ll get a “missing implementation” error.
- The path to native dir must end with ” .”, or you’ll get a “missing implementation” error.
- The signing server returned errors about a missing timestamp
- No default implementation was provided
The first two issues are simple to solve once you understand what the problem is.
Regarding the signing server, I’m not sure what’s up with this one, but the good news is that signing is no longer a requirement for ANE’s. So I’ve just ommitted it from my script.
The final thing is the lack of a ‘default’ platform. All ANE’s should have a default implementation, I’m really not sure why Adobe even made this optional. Without it, you can not run your application on devices that the ANE doesn’t support, including your own development machine! So default implementations are a must, always always always include this!
Without further ado, here’s an improved build script which addresses the above issues:
0 1 2 3 4 5 6 7 8 9 10 11
set ADT=F:\Program Files\Adobe FlashBuilder 4.6\Adobe Flash Builder 4.6\sdks\4.6.0\bin\adt set SWC_DIR=F:\esdot.ca\Experimental\2012.VibrationExtension.SWC\bin set SWC=%SWC_DIR%\2012.VibrationExtension.SWC.swc set XML=%SWC_DIR%\extension.xml set ANDROID_PLATFORM= -platform Android-ARM -C %SWC_DIR%\Android-ARM\ . set DEFAULT_PLATFORM= -platform default -C %SWC_DIR%\default\ . set OUTPUT=./vibration.ane "%ADT%" -package -target ane "%OUTPUT%" "%XML%" -swc "%SWC%" %ANDROID_PLATFORM% %DEFAULT_PLATFORM%
That script should run for you without issue, and I think is a bit more clear to understand. Also, you can see how you’d easily add new platforms to this without much effort.
You’ll also need to modify your extensions.xml file slightly, in order to add the default platform support:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<extension xmlns="http://ns.adobe.com/air/extension/2.5"> <id>com.esdot.ane.Vibration</id> <versionNumber>1</versionNumber> <platforms> <platform name="Android-ARM"> <applicationDeployment> <nativeLibrary>vibration.jar</nativeLibrary> <initializer>com.esdot.ane.vibration.VibrationExtension</initializer> </applicationDeployment> </platform> <platform name="default"> <applicationDeployment/> </platform> </platforms> </extension>
Hopefully that helps someone out there! You can download the working FlashBuilder project here, which contains everything needed to spit out a build: