适用于 Android 的 Adob​​e AIR 3.1 本机扩展 - Actionscript 中的空扩展上下文

发布于 12-28 16:05 字数 3179 浏览 6 评论 0原文

我正在开发适用于 Android 平台的本机扩展,但我遇到了困难...

针对 Android 2.1...在 Google Nexus One (2.3.6) 上测试

此行返回 NULL

this.context = ExtensionContext.createExtensionContext("com.company.ane.LocationManager", "");

这是扩展描述符文件:

<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>

这是我的包命令:

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这个阶段扩展非常简单...我只是想将字符串值返回到我的应用程序...

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'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

}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

随波逐流2025-01-04 16:05:22

我有完全相同的问题。
我的 ANE 在 iOS 模拟器上运行良好,使用了默认库,但在实际的 Android 设备(Android-ARM 平台)上无法运行。

并且 ExtensionContext.createExtensionContext() 返回 null

原来这个问题是tools版本问题,Java编译器版本问题。我使用的是最新的 AIR (3.8)、JDK (1.7.25)、Android SDK (22.0.5) 等。它不起作用。

但在将 -target 1.6 添加到 javac 调用后,效果很好。

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.

(り薆情海2025-01-04 16:05:22

最基本的扩展仍然包括2个类。

您需要实现 FREExtension 接口:

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() 
{
}
}

然后上下文就是您上面的类:

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;
}
}

扩展 xml 中的类应该是这里的第一个类,即 FREExtension 实现。

另外,除非您要创建此扩展的 iPhone 版本,否则您应该从您的 extension.xml 中删除 iPhone 节点。

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.

墨小墨2025-01-04 16:05:22

我之前确实遇到过同样的问题,实际上问题不是 createExtensionContext() 函数本身,而是类 FREContext 并且大多数时候它发生在方法 public Map getFunctions() 中

基本上,例如我已经声明了 3 个 FREFunctions 来使用我的 FREContext 就像:

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)

因此,当初始化 FREContext 时,此类将遍历内部每个函数的构造函数,如果我在 getVersion() 函数的构造函数中的某个地方遇到一些异常,FREContext 将崩溃并将 null 返回给 createExtensionContext()。
解决这个问题的方法是,如果你不确定哪里出现了异常,就将你的所有 FREFunction 一一注释掉,找出是哪一个导致了异常。
就您而言,我怀疑这两个变量

  public LocationManager locationManager;
  public LocationListener locationListener;

是导致异常的原因。请注释掉它们并重试。
在构建 ANE 时对您有很大帮助的另一件事是尝试通过将当前 AIR android 应用程序的端口附加到 ADT 的调试器来从 ADT 调试 ANE。您可以从本文 http://www.adobe.com/devnet/air/articles/ane-android-devices.html" rel="nofollow">http:// /www.adobe.com/devnet/air/articles/ane-android-devices.html

希望有帮助。

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.

贱贱哒2025-01-04 16:05:22

你从哪里得到 NULL 引用?这是在设备上还是在 AIR 模拟器中运行?

如果无法找到当前正在运行的平台(例如:Windows 模拟器)的 ExtensionContext,则返回 NULL,即使它可能在设备上运行良好。您可以在编译 ANE 时设置默认上下文,该上下文将在未找到特定匹配的情况下使用。这个默认目标可以完全用 AS3 编写,对于伪造或处理不受支持的设备很有用。

Adobe AIR 文档提供了有关默认实现的更多详细信息。请参阅此处:http://help.adobe.com/en_US/air/extensions/WSf268776665d7970d-2482335412ffea65006-8000.html

编辑:哎呀,我看到你正在运行设备。我仍然会尝试默认的,看看是否可以正常工作,这可能有助于缩小问题范围。

编辑 2: 您是否正在实现 FREExtension 接口(在 Java 中)?我在您发布的代码中没有看到这一点。

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.

ヤ经典坏疍2025-01-04 16:05:22

我在尝试构建 ANE-Video 时遇到了同样的问题:

_context = ExtensionContext.createExtensionContext(EXTENSION_ID, null);

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

我通过编译解决了问题使用 1.6 JDK 而不是 1.7 JDK(在 Mac OS X Mavericks 上运行)。

这篇文章 帮助暂时将 JDK 回滚到 1.6。

线索来自这篇 Adob​​e 文章

目前 Adob​​e 工具与 Java 7 不太兼容,您可能在链接和打包时遇到错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文