airflex4flash-builderflex-mobileair-native-extension

Adobe ANE works on iOS and Android devices, but not in AIR simulator


The vibration ane by Adobe works well in a Flex mobile app both on iOS and Android, but when I try to launch an AIR simulator from Flash Builder 4.7 on Windows 7 I get the error:

enter image description here

enter image description here

Here a copy of the error message from the latter screenshot:

Process terminated without establishing connection to debugger.

The content cannot be loaded because there was a problem loading an extension: Error: Requested extension com.adobe.Vibration is not supported for Windows-x86.

Launch command details:  "C:\Program Files\Adobe\Adobe Flash Builder 4.7 (64 Bit)\sdks\4.6.0 (AIR 3.5)\bin\adl.exe" -runtime "C:\Program Files\Adobe\Adobe Flash Builder 4.7 (64 Bit)\sdks\4.6.0 (AIR 3.5)\runtimes\air\win" -profile extendedMobileDevice -screensize 640x920:640x960 -XscreenDPI 326 -XversionPlatform IOS -extdir "C:\Users\xxx\Adobe Flash Builder 4.7\.metadata\.plugins\com.adobe.flexbuilder.project.ui\ANEFiles\MyApp-Mobile\win32\" C:\Users\xxx\Documents\MyApp\mobile\bin-debug\MyApp-app.xml C:\Users\xxx\Documents\MyApp\mobile\bin-debug 

At the same time:

  1. Another ANE by Adobe - the GameCenter.ane included with Adobe Gaming SDK works flawlessly with the AIR Simulator

  2. The com.adobe.extensions.Vibration.ane mentioned above doesn't fail when I select the BlackBerry AIR simulator (but the iOS and Android AIR Simulators do not work).

Is there a way to make this work more comfortable?

I'd like to use the com.adobe.extensions.Vibration.ane in my Flex mobile app, but I also want to use the AIR simulator - without commenting the source code and removing that ANE from project properties.

UPDATE 2016:

Adobe has updated their Vibration native extension (ANE) sample with 64-bit support.


Solution

  • The problem with the ANE is that it's not a complete implementation. Most importantly the ANE doesn't implement a default fallback implementation which is what the device would fallback to if there wasn't a particular implementation for the current platform.

    This makes the ANE very hard to use in cross-platform development as it will fail in some cases. Any platform that isn't specifically included will fail with the message you received.

    Basically without changing the ANE yourself you won't be able to use it as you are expecting. Your only way is to do some conditional style compilation and not call the ANE in the simulator.

    If you do wish to change the ANE then the best option is to implement the default library. This is quite simple, but you will need: XCode, eclipse with Android dev tools, and adt from the AIR SDK.

    Firstly you'll need to compile the existing projects, the Android lib, the iOS lib and the existing actionscript library, to generate VibrationAndroidLibrary.jar, libVibrationiOSLibrary.a and VibrationActionScriptLibrary.swc respectively.

    You'll then need to make another actionscript library, and duplicate the com.adobe.nativeExtensions.Vibration class as below:

    public class Vibration
    {
        public function Vibration()
        {
        }
    
        public static function get isSupported():Boolean
        {
            return false;
        }
    
        public function vibrate(duration:Number):void
        {
        }
    }
    

    This class will replace the other class in cases where the extension isn't implemented instead of you getting the above message.

    Then we'll need to add the default definition to the extension.xml file:

    <extension xmlns="http://ns.adobe.com/air/extension/2.5">
        <id>com.adobe.Vibration</id>
        <versionNumber>1</versionNumber>
        <platforms>
            <platform name="Android-ARM">
                <applicationDeployment>
                    <nativeLibrary>VibrationAndroidLibrary.jar</nativeLibrary>
                    <initializer>air.extensions.VibrationExtension</initializer>
                    <finalizer>air.extensions.VibrationExtension</finalizer>
                </applicationDeployment>
            </platform>
            <platform name="iPhone-ARM">
            <applicationDeployment>
                <nativeLibrary>libVibrationiOSLibrary.a</nativeLibrary>
                <initializer>ExtInitializer</initializer>
                <finalizer>ExtFinalizer</finalizer>
                </applicationDeployment>
            </platform>
    
            <platform name="default"> 
                <applicationDeployment /> 
            </platform>
    
        </platforms>
    </extension>
    

    Then we'll need to recompile the ANE using the new default actionscript SWC. Lets say you're in the VibrationNEDeliverables directory from the mentioned ANE, you can enter this into a bash file and run it or put it all on one line from the command line). The first couple of lines just extract the library.swf file and move it to the locations needed by the package command. Be careful with the paths etc here, I've assumed you've put the default lib in VibrationActionScriptDefaultLibrary but you'll need to change this appropriately.

    unzip -o -d VibrationActionScriptLibrary/bin VibrationActionScriptLibrary/bin/VibrationActionScriptLibrary.swc
    unzip -o -d VibrationActionScriptDefaultLibrary/bin VibrationActionScriptDefaultLibrary/bin/VibrationActionScriptDefaultLibrary.swc 
    
    cp VibrationActionScriptLibrary/bin/library.swf VibrationiOSLibrary/build/Release-iphoneos/.
    cp VibrationActionScriptLibrary/bin/library.swf VibrationAndroidLibrary/bin/.
    
    adt -package \
        -storetype pkcs12 -keystore YOUR_SIGNING_KEY.p12 -storepass KEY_PASSWORD \
        -target ane com.adobe.extensions.Vibration.ane VibrationActionScriptLibrary/src/extension.xml \
        -swc VibrationActionScriptLibrary/bin/VibrationActionScriptLibrary.swc \
        -platform iPhone-ARM  -C VibrationiOSLibrary/build/Release-iphoneos . \
        -platform Android-ARM -C VibrationAndroidLibrary/bin . \
        -platform default -C VibrationActionScriptDefaultLibrary/bin .
    

    Once that's complete you should now have a new version of the ANE with a default lib which will make it much more useable! Personally I don't think an ANE should be released without it.

    If you need a fully functional ANE, you can check out ours: http://distriqt.com/native-extensions