Tutorial: Packaging ANE’s

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…

Folder Structure

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”

When you’re all done, what we want to see is this:

If you have something like that, you’re good to go on to the next step.

Build Script

I had a couple issues with the build script posted in the tutorial. Specifically I hit these gotcha’s:

  1. The path to native_dir must NOT be wrapped in quotes, or you’ll get a “missing implementation” error.
  2. The path to native dir must end with ” .”, or you’ll get a “missing implementation” error.
  3. The signing server returned errors about a missing timestamp
  4. 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:

Written by

4 Comments to “Tutorial: Packaging ANE’s”

  1. Ken says:

    I recently tried your photo retouch, the free app version and was very satisfied. Upon finishing retouching my first photo i got the message about upgrading. Well upon seeing “support an indie developer trying to raise a family” in your list of benefits to upgrading I just couldn’t resist;)
    Good luck man! I’m looking forward to checking out some of your other apps.
    -KT
    (sorry, i know this probably isn’t the best place for my comment)

  2. Walex says:

    Hi Shawn, thanks for the post, it was very helpful. I did have to add one little tweak to mine. Because there was a space in my SWC_DIR I had to put quotes around %SWC_DIR% when setting the platforms. Code posted below.

    set ANDROID_PLATFORM= -platform Android-ARM -C “%SWC_DIR%”\Android-ARM\ .
    set DEFAULT_PLATFORM= -platform default -C “%SWC_DIR%”\default\ .

  3. Steve says:

    THANKS! Just what I needed to fine tune that build script.

  4. Andrew says:

    Hi, this is kind of silly question but I really dont know where should i put this script.. do I make a .bat file for this or just write it down on command line? i meant this script

    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%

    thanks in advance :)

Leave a Reply to Ken

Message