Two ane file conflict in one flex mobile application

110 views Asked by At

I have two ane file for video recorder. One is for android and another is for ios device. Both have different package name and methods.

Now, i import both Native Extension in single project. And detect ios and android device following way:

if(Capabilities.version.indexOf('IOS') > -1) //for ios device

And

if(Capabilities.version.indexOf('AND') > -1) //for android device

And create object for each class. Now when i run that it gives error for another ane class not found.

Like Suppose i check in ios then gives error for android ane file class, Event not found. same for android.

2

There are 2 answers

5
BotMaster On BEST ANSWER

If you have an ANE that only supports Android it won't be available at all when run in Ios (same is true for Ios). If it has a default implementation its classes will be available but if it doesn't then its classes will just not exist in that scope and error will be thrown if you try to reference them. When using ANE that only offer one platform implementation those ANE have to be used only when compiling for that platform. The way you can switch between ANEs easily is by using CONFIG constants.

EDIT: Defining constants. Right Click project and choose "properties", in "Actionscript compiler" add as many config lines as you see fit, for example:

-define=CONFIG::ANDROID,false
-define=CONFIG::IOS,false

Now wrap all code (including import statements) referencing the Android ANE and the IOS ANE with:

CONFIG::ANDROID
{
    //android code here
}
CONFIG::IOS
{
    //ios code here
}

Now your 2 config variables are set to false so no code in between "CONFIG::ANDROID" or "CONFIG::IOS" will be compiled with your app. Now if in "actionscript compiler" you change:

-define=CONFIG::ANDROID,true

All code that is in between "CONFIG::ANDROID" will be compiled (you can use "CONFIG::ANDROID" anywhere in your code as many times as you want).

So before compiling set one config to true and make sure the other is set to false and the right code for the right platform will be compiled.

0
Adrian Pirvulescu On

Capabilities.version will tell you: "Specifies the Flash Player or AdobeĀ® AIRĀ® platform and version information." and not the OS version you are running on.

See here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html#version

You need to use Capabilities.os instead http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html#os