I'm working on Native Extension for Android platform and i got stuck...
Targeting Android 2.1... testing on Google Nexus One (2.3.6)
this line returns NULL
this.context = ExtensionContext.createExtensionContext("com.company.ane.LocationManager", "");
this is extension descriptor file:
<extension xmlns="http://ns.adobe.com/air/extension/3.1">
<id>com.company.ane.LocationManager</id>
<versionNumber>0.0.1</versionNumber>
<platforms>
<platform name="iPhone-ARM">
<applicationDeployment>
<nativeLibrary>libANELocationManager.a</nativeLibrary>
<initializer>ExtInitializer</initializer>
<finalizer>ExtFinalizer</finalizer>
</applicationDeployment>
</platform>
<platform name="Android-ARM">
<applicationDeployment>
<nativeLibrary>libANELocationManager.jar</nativeLibrary>
<initializer>com.company.ane.android.ANELocationManager</initializer>
</applicationDeployment>
</platform></platforms></extension>
that is my package command:
adt -package -target ane ./../../app/libs/locationmanager.ane ./../extension.xml -swc ane_location_manager.swc -platform iPhone-ARM library.swf libANELocationManager.a -platform Android-ARM library.swf libANELocationManager.jar
At this stage extension is really simple... i'm just trying to return string value back to my app...
package com.company.ane.android;
import java.util.HashMap;
import java.util.Map;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import android.location.LocationListener;
import android.location.LocationManager;
public class ANELocationManagerContext extends FREContext {
public LocationManager locationManager;
public LocationListener locationListener;
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public Map<String, FREFunction> getFunctions() {
Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();
functionMap.put("ExtensionTest", new ExtensionTest());
return functionMap;
}
}
package com.company.ane.android;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import com.adobe.fre.FREWrongThreadException;
public class ExtensionTest implements FREFunction {
@Override
public FREObject call(FREContext context, FREObject[] args) {
FREObject result = null;
//ANELocationManagerContext ctx = (ANELocationManagerContext) context;
try
{
result = FREObject.newObject("It works!");
}
catch (FREWrongThreadException fwte)
{
fwte.printStackTrace();
}
return result;
}
}
package com.company.ane.android;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
public class ANELocationManager implements FREExtension {
@Override
public FREContext createContext(String contextType) {
return new ANELocationManagerContext();
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void initialize() {
// TODO Auto-generated method stub
}
}
I had exactly same issue. My ANE was working fine on iOS, on simulator, with default lib used, but wasn't working on actual Android device (Android-ARM platform).
And ExtensionContext.createExtensionContext()
was returning null
.
It turned out that this problem is tools version problem, Java compiler version. I was using latest AIR (3.8), JDK (1.7.25), Android SDK (22.0.5) etc. It didn't work.
But after adding -target 1.6
to javac
call, it worked well.
The most basic extension still includes 2 classes.
You need to implement the FREExtension interface:
package com.your.package;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
public class YourExtension implements FREExtension
{
public static FREContext context;
@Override
public FREContext createContext(String contextType)
{
return context = new YourContext();
}
@Override
public void dispose()
{
context = null;
}
@Override
public void initialize()
{
}
}
And then the context is the class you have above:
package com.your.package;
import java.util.HashMap;
import java.util.Map;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
public class YourContext extends FREContext
{
@Override
public void dispose()
{
}
@Override
public Map<String, FREFunction> getFunctions()
{
Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();
// Create your map
return functionMap;
}
}
The class in the extension xml should be the first one here, i.e. the FREExtension implementation.
Also unless you are creating the iPhone version of this extension you should remove the iPhone node from your extension.xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With