Adobe AIR 3.1 Native Extension for Android - null extension context in actionscript
Asked Answered
S

5

10

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

}

}
Swede answered 23/1, 2012 at 19:33 Comment(1)
Did you ever find a solution? ANEs that I created a while back were fine. Today when im making new ones, i'm getting your exact error. Even with code i did a few months back and I didnt change anything...Converse
P
7

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.

Pretender answered 2/8, 2013 at 19:56 Comment(0)
R
3

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.

Rabe answered 24/1, 2012 at 22:14 Comment(1)
The next thing to check is that you are actually packaging the extension with your application. You can follow something like this: labs.distriqt.com/post/815. Just check you have the "Package" check box ticked for each of the build packaging platforms. Are you using FB4.6?Rabe
W
2

I did get the same problem before and actually the problem was not the createExtensionContext() function itself but the class FREContext and most of the time it happend in the method public Map getFunctions()

Basically, for example I have declared 3 FREFunctions to use in my FREContext like :

functionMap.put("initMe", new initFunction() );
functionMap.put("getVersion", new getVersion() );
functionMap.put("showBrowser", new showBrowser() ); // For example, I got some exceptions in this function as I declare some Java variable that is not supported by the current Android SDK version like LocationManager (for example)

So when the FREContext is initialized, this class will goes through the constructor of each function inside and if I got some exceptions somewhere in the constructor of getVersion() function, the FREContext will crash and return null back to createExtensionContext(). The solution to this problem is if you are not sure where you get the exception, comment out all your FREFunction one by one to figure out which one cause the exception. In your case, I doubt the 2 variables

  public LocationManager locationManager;
  public LocationListener locationListener;

are the causes of the Exception. Please comment them out and try again. Another thing that can help you a lot when building the ANE is trying to debug the ANE from your ADT by attach the current AIR android app's port to ADT's debugger. You can learn more about how to debug ANE from this article http://www.adobe.com/devnet/air/articles/ane-android-devices.html

Hope it helps.

Wichern answered 4/4, 2014 at 0:21 Comment(0)
S
1

Where are you getting the NULL reference? Is this running on device or in the AIR simulator?

If ExtensionContext can not be found for the current platform you are running on (eg: windows simulator) NULL is returned, even though it might run fine on the device. You can setup a default context when compiling the ANE that would be used where ever specific match is not found. This default target can be written entirely in AS3, and is useful for faking or handling unsupported devices.

The Adobe AIR documentation has more details on including a default implementation. See here: http://help.adobe.com/en_US/air/extensions/WSf268776665d7970d-2482335412ffea65006-8000.html

EDIT: Whoops, I see you are running on device. I'd still try a default one and see if you can get that working, it might help narrow down the problem.

EDIT 2: Are you Implementing the FREExtension interface (in Java)? I don't see that in your posted code.

Scheming answered 23/1, 2012 at 22:11 Comment(7)
Its hard to track down the problem without looking at all the Java code, that portion of the code could be where the bug exists. When you can I'd recommend comparing that with Adobe's docs to make sure its initializing the context correctly.Scheming
I'll add the missing bit when I have access to the rest of the code... Left it in the office... But I'm quite sure it's fine... I'd rather think there must be something wrong with the setup or the way I package the whole thing...Swede
Is it normal situation that if i test it in simulator it loads "default" extension?Swede
Yes, default loads everywhere It can find another context for.Scheming
I checked everything I could... It works on IPhone... works in Android simulator using default extension, but i still get this reference error on Android device... any clues? Could this be something with the way i create JAR file?Swede
I have Same Issue. And Search from last 2 days but didn't get any solution.Mahone
What version of Air SDK were you using? I had the same issue, until I downloaded the latest SDK from here: helpx.adobe.com/air/kb/archived-air-sdk-version.htmlEpicedium
M
0

I ran into the same problem when trying to build ANE-Video:

_context = ExtensionContext.createExtensionContext(EXTENSION_ID, null);

// _context is set to null, with no other error info

I solved the problem by compiling with a 1.6 JDK instead of a 1.7 JDK (running on Mac OS X Mavericks).

This post helped temporarily roll the JDK back to 1.6.

The clue came from this Adobe article:

At this point Adobe tooling is not quite compatible with Java 7 and you may run into errors at linking and packaging time.

Mccaslin answered 25/9, 2014 at 17:41 Comment(2)
Why were you passing null in the parameter?Epicedium
I passed null because this indicates that contextType is not specified. See Adobe's ExtensionContext docs.Mccaslin

© 2022 - 2024 — McMap. All rights reserved.