Flex Mobile AIR Native 扩展错误

发布于 2024-12-20 19:45:40 字数 7970 浏览 1 评论 0原文

我目前正在致力于为本机警报弹出窗口创建 Android ANE。我现在认为我的 Java 和 AS3 代码都可以使用,但是当我尝试使用它时出现错误。

主线程(挂起:TypeError:错误#1009:无法访问空对象引用的属性或方法。)

我的问题是我真的不确定这个错误来自哪里。我的想法是,我没有正确构建 ANE 文件,或者我的 extension.xml 文件中有问题,但我真的不太确定。

我将尽力提供有关如何建立该项目的尽可能多的信息。现在我正在尝试在小型测试应用程序中使用此 ANE。

首先,文件夹设置:

ANEextensions-

     Alert_Java (holding my Java project)

          (Android/Java created assets. Not sure if these are important or now. If so I will list them)

          src

               com

                    fa

                         ne                        

                              android

                                   AlertContext.java

                                   AlertExtension.java

                                   ShowAlert.java

     Alert_AS

          bin

               AlertAndroidAS.swc

          src

               Alert.as

               extension.xml

我不会费心发布我的 java 代码,因为我认为它是正确的。但如果有人愿意花一些时间帮助我解决这个问题想看一下,请告诉我。

这是我的 extensions.xml 文件

<extension xmlns="http://ns.adobe.com/air/extension/2.5">

<id>com.fa.alerts</id>

<versionNumber>1.0</versionNumber>

    <platforms>

        <platform name="Android-ARM">

            <applicationDeployment>

                <nativeLibrary>AndroidAlert.jar</nativeLibrary>

                <initializer>com.fa.ne.android.AlertExtension</initializer>

                <finalizer>com.fa.ne.android.AlertExtension</finalizer>

            </applicationDeployment>

        </platform>

    </platforms>

</extension>

这是我的 Alert.as 文件:

package {

    import flash.events.EventDispatcher;

    import flash.external.ExtensionContext;



    public class Alert extends EventDispatcher{

        public static var extContext:ExtensionContext = null

        public function Alert(){

            super();



            extContext = ExtensionContext.createExtensionContext("com.fa.alerts", null);



        }



        public static function androidAlert(aTitle:String, aMsg:String, aNeg:String = "Cancel", aPos:String = "Ok"):void{

            extContext.call("showAlert", aTitle, aMsg, aNeg, aPos);

        }

    }

}

这是我用来测试的存根应用程序

<?xml version="1.0" encoding="utf-8"?>

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 

        xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">



    <fx:Script>

        <![CDATA[



            protected function spawnAne(event:MouseEvent):void{



                var a:Alert = new Alert();

                Alert.androidAlert("test","testing");

            }

        ]]>

    </fx:Script>



    <fx:Declarations>

        <!-- Place non-visual elements (e.g., services, value objects) here -->

    </fx:Declarations>

    <s:Button click="spawnAne(event)" />

</s:View>

现在单击该按钮就是导致错误的原因。

我的测试应用程序和 AS3 Alert_AS 项目之间没有任何类型的 SWC 或链接。我正在使用 Flash Builder 4.6 通过 IDE 工具导入 ANE 文件。

为了构建我的 ANE,我使用了这篇文章中稍微修改过的 bash 脚本:http://gotoandlearn。 com/play.php?id=149 作者:Lee Brimelow

# path to YOUR Android SDK
export AIR_ANDROID_SDK_HOME="my sdk"

# path to the ADT tool in Flash Builder sdks
ADT="my adt"

# native project folder
NATIVE_FOLDER=Alert_Java

# AS lib folder
LIB_FOLDER=Alert_AS

# name of ANE file
ANE_NAME=AndroidAlert.ane

# JAR filename
JAR_NAME=AndroidAlert.jar


# cert path
CERT_NAME=cert.p12

# cert password
CERT_PASS=password

#===================================================================

echo "****** preparing ANE package sources *******"

rm ${ANE_NAME}
rm -rf ./build/ane
mkdir -p ./build/ane
mkdir -p ./build/ane/Android-ARM
mkdir -p ./build/ane/Android-ARM/res

# copy resources
cp -R ./${NATIVE_FOLDER}/res/* ./build/ane/Android-ARM/res

# create the JAR file
jar cf ./build/ane/Android-ARM/${JAR_NAME} -C ./${NATIVE_FOLDER}/bin .

# grab the extension descriptor and SWC library 
cp ./${LIB_FOLDER}/src/extension.xml ./build/ane/
cp ./${LIB_FOLDER}/bin/*.swc ./build/ane/
unzip ./build/ane/*.swc -d ./build/ane
mv ./build/ane/library.swf ./build/ane/Android-ARM


echo "****** creating ANE package *******"

"$ADT" -package -storetype PKCS12 -keystore ./cert.p12 -storepass password -tsa none \
    -target ane \
    ${ANE_NAME} \
    ./build/ane/extension.xml \
    -swc ./build/ane/*.swc \
    -platform Android-ARM \
    -C ./build/ane/Android-ARM/ .

echo "****** ANE package created *******"

我知道这有点长,但任何帮助将不胜感激!如果您需要更多详细说明,请随时告诉我

添加了 Java 代码

我对原始代码进行了一些修改。我删除了 AlertExtension.java 并将获取上下文函数移至 AlertContext.java。我以为这会解决我的问题,但我仍然得到相同的结果。这是我的代码:

AlertContext.java,我假设 createContext 方法在 var a:Alert = new Alert(); 之后触发

package com.fa.ne.android;

import java.util.Map;
import java.util.HashMap;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
import com.adobe.fre.FREFunction;

public class AlertContext extends FREContext implements FREExtension {

@Override
public FREContext createContext(String type){
    return new AlertContext();
}

@Override
public void initialize(){

}
@Override
public void dispose() {

}

@Override
public Map<String, FREFunction> getFunctions() {

    HashMap<String, FREFunction> functionMap = new HashMap<String, FREFunction>(); 
    functionMap.put("showAlert", new ShowAlert());
    return functionMap;
}




}

这是我的 ShowAlert 课程

package com.fa.ne.android;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;


public class ShowAlert implements FREFunction {

@Override
public FREObject call(FREContext aContext, FREObject[] aPassedArgs) {
    //get activity
    Activity a = aContext.getActivity();
    //grabbing context
    final FREContext context = aContext; 
    try{
        //getting the title and msg for alert as string
        String title = aPassedArgs[0].getAsString();
        String message = aPassedArgs[1].getAsString();
        String negitive = aPassedArgs[3].getAsString();
        String positive = aPassedArgs[4].getAsString();
        //creating the alert builder with the activity
        Builder builder = new Builder(a);
        //setting the title and msg
        builder.setTitle(title);
        builder.setMessage(message);
        //setting up buttons, negative and positive, each with an event so we can listen in AS3
        //doing listeners inline
        builder.setNegativeButton(negitive, new OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int dig){
                context.dispatchStatusEventAsync("nativeAlert", "negitive");
            }

        }).setNeutralButton(positive, new OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int dig){
                context.dispatchStatusEventAsync("positiveAlert", "positive");
            }
        });
        //done building, time to alert and return
        builder.create().show();

        return FREObject.newObject(true);

        //error handeling
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (FRETypeMismatchException e) {
        e.printStackTrace();
    } catch (FREInvalidObjectException e) {
        e.printStackTrace();
    } catch (FREWrongThreadException e) {
        e.printStackTrace();
    }

    return null;
}

}

I'm currently working on creating an Android ANE for native alert popups. I'm now at the point where I think my both my Java and AS3 code is good to go but I'm getting an error when I try to use it.

Main Thread (Suspended: TypeError: Error #1009: Cannot access a property or method of a null object reference.)

My problem is I'm really not sure where this error is coming from. My thinking is that I'm not building the ANE file correctly or something is wrong in my extension.xml file but I'm really not too sure.

I'm going to try to provide as much information as I can about how this project is set up. Right now I'm trying to use this ANE in a small, testing application.

First, the folder setup:

ANEextensions-

     Alert_Java (holding my Java project)

          (Android/Java created assets. Not sure if these are important or now. If so I will list them)

          src

               com

                    fa

                         ne                        

                              android

                                   AlertContext.java

                                   AlertExtension.java

                                   ShowAlert.java

     Alert_AS

          bin

               AlertAndroidAS.swc

          src

               Alert.as

               extension.xml

I'm not going to bother posting my java code as I think it's correct. but if anyone who is willing to invest some time in helping me with this issue wants to take a look please let me know.

This is my extensions.xml file

<extension xmlns="http://ns.adobe.com/air/extension/2.5">

<id>com.fa.alerts</id>

<versionNumber>1.0</versionNumber>

    <platforms>

        <platform name="Android-ARM">

            <applicationDeployment>

                <nativeLibrary>AndroidAlert.jar</nativeLibrary>

                <initializer>com.fa.ne.android.AlertExtension</initializer>

                <finalizer>com.fa.ne.android.AlertExtension</finalizer>

            </applicationDeployment>

        </platform>

    </platforms>

</extension>

And this is my Alert.as file:

package {

    import flash.events.EventDispatcher;

    import flash.external.ExtensionContext;



    public class Alert extends EventDispatcher{

        public static var extContext:ExtensionContext = null

        public function Alert(){

            super();



            extContext = ExtensionContext.createExtensionContext("com.fa.alerts", null);



        }



        public static function androidAlert(aTitle:String, aMsg:String, aNeg:String = "Cancel", aPos:String = "Ok"):void{

            extContext.call("showAlert", aTitle, aMsg, aNeg, aPos);

        }

    }

}

And this is my stub app I'm using to test

<?xml version="1.0" encoding="utf-8"?>

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 

        xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">



    <fx:Script>

        <![CDATA[



            protected function spawnAne(event:MouseEvent):void{



                var a:Alert = new Alert();

                Alert.androidAlert("test","testing");

            }

        ]]>

    </fx:Script>



    <fx:Declarations>

        <!-- Place non-visual elements (e.g., services, value objects) here -->

    </fx:Declarations>

    <s:Button click="spawnAne(event)" />

</s:View>

Now clicking on that button is what causes the error.

I don't have any kind of swc or link between my testing app and the AS3 Alert_AS project. I'm using Flash Builder 4.6 to import the ANE file using the IDE tools.

To build my ANE I'm using a lightly modified bash script from this post: http://gotoandlearn.com/play.php?id=149 by Lee Brimelow

# path to YOUR Android SDK
export AIR_ANDROID_SDK_HOME="my sdk"

# path to the ADT tool in Flash Builder sdks
ADT="my adt"

# native project folder
NATIVE_FOLDER=Alert_Java

# AS lib folder
LIB_FOLDER=Alert_AS

# name of ANE file
ANE_NAME=AndroidAlert.ane

# JAR filename
JAR_NAME=AndroidAlert.jar


# cert path
CERT_NAME=cert.p12

# cert password
CERT_PASS=password

#===================================================================

echo "****** preparing ANE package sources *******"

rm ${ANE_NAME}
rm -rf ./build/ane
mkdir -p ./build/ane
mkdir -p ./build/ane/Android-ARM
mkdir -p ./build/ane/Android-ARM/res

# copy resources
cp -R ./${NATIVE_FOLDER}/res/* ./build/ane/Android-ARM/res

# create the JAR file
jar cf ./build/ane/Android-ARM/${JAR_NAME} -C ./${NATIVE_FOLDER}/bin .

# grab the extension descriptor and SWC library 
cp ./${LIB_FOLDER}/src/extension.xml ./build/ane/
cp ./${LIB_FOLDER}/bin/*.swc ./build/ane/
unzip ./build/ane/*.swc -d ./build/ane
mv ./build/ane/library.swf ./build/ane/Android-ARM


echo "****** creating ANE package *******"

"$ADT" -package -storetype PKCS12 -keystore ./cert.p12 -storepass password -tsa none \
    -target ane \
    ${ANE_NAME} \
    ./build/ane/extension.xml \
    -swc ./build/ane/*.swc \
    -platform Android-ARM \
    -C ./build/ane/Android-ARM/ .

echo "****** ANE package created *******"

I know this is a bit long but any help would be greatly appreciated! And feel free to let me know if you need some more elaboration

Added Java code

I modified the original code a bit. I removed AlertExtension.java and moved the get context function to AlertContext.java. I was thinking this would solve my issue but I'm still getting the same result. Here is my code:

AlertContext.java, I'm assuming the createContext method is fired after var a:Alert = new Alert();

package com.fa.ne.android;

import java.util.Map;
import java.util.HashMap;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
import com.adobe.fre.FREFunction;

public class AlertContext extends FREContext implements FREExtension {

@Override
public FREContext createContext(String type){
    return new AlertContext();
}

@Override
public void initialize(){

}
@Override
public void dispose() {

}

@Override
public Map<String, FREFunction> getFunctions() {

    HashMap<String, FREFunction> functionMap = new HashMap<String, FREFunction>(); 
    functionMap.put("showAlert", new ShowAlert());
    return functionMap;
}




}

Here is my ShowAlert class

package com.fa.ne.android;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;


public class ShowAlert implements FREFunction {

@Override
public FREObject call(FREContext aContext, FREObject[] aPassedArgs) {
    //get activity
    Activity a = aContext.getActivity();
    //grabbing context
    final FREContext context = aContext; 
    try{
        //getting the title and msg for alert as string
        String title = aPassedArgs[0].getAsString();
        String message = aPassedArgs[1].getAsString();
        String negitive = aPassedArgs[3].getAsString();
        String positive = aPassedArgs[4].getAsString();
        //creating the alert builder with the activity
        Builder builder = new Builder(a);
        //setting the title and msg
        builder.setTitle(title);
        builder.setMessage(message);
        //setting up buttons, negative and positive, each with an event so we can listen in AS3
        //doing listeners inline
        builder.setNegativeButton(negitive, new OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int dig){
                context.dispatchStatusEventAsync("nativeAlert", "negitive");
            }

        }).setNeutralButton(positive, new OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int dig){
                context.dispatchStatusEventAsync("positiveAlert", "positive");
            }
        });
        //done building, time to alert and return
        builder.create().show();

        return FREObject.newObject(true);

        //error handeling
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (FRETypeMismatchException e) {
        e.printStackTrace();
    } catch (FREInvalidObjectException e) {
        e.printStackTrace();
    } catch (FREWrongThreadException e) {
        e.printStackTrace();
    }

    return null;
}

}

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

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

发布评论

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

评论(4

过潦 2024-12-27 19:45:41

我实在无法回答你的问题。我不懂 Java(对我来说它读起来就像伪 ActionScript 嘿嘿嘿)。然而,这可能会为您提供一些帮助和帮助。您可以向这里推荐一个可能很容易发现问题的人。

Piotr Walczyszyn 在这里创建了一个 Android 原生警报/推送扩展:
http://www.riaspace.com/2011/09/as3c2dm-air-native-extension-to-push-notifications-with-c2dm/" riaspace.com/2011/09/as3c2dm-air-native-extension-to-push-notifications-with-c2dm/

在评论中我也在这里找到了另一个人,他提供了有关 iOS 原生警报的详细教程:http://www.liquid-photo.com/2011/10/28/native-extension-for-adobe-air-and-ios-101/

我正在阅读以下评论Piotr 的帖子和他所说的一些事情让我想知道这条线是否

extContext = ExtensionContext.createExtensionContext("com.fa.alerts", null);

可能导致/与问题相关

希望这可以帮助您和/或其他人。

祝大家好运!

托德

……回到研究推送通知选项/可行性
=D

I can't really answer your question. I don't know Java (it reads like pseudo ActionScript for me heehhehee). However, this might offer you some help & someone you could refer back here who might spot the problem easily.

Piotr Walczyszyn created an Android native alert / push extension here:
http://www.riaspace.com/2011/09/as3c2dm-air-native-extension-to-push-notifications-with-c2dm/

In the comments I also found another person with an extensive tutorial for native alerts in iOS here: http://www.liquid-photo.com/2011/10/28/native-extension-for-adobe-air-and-ios-101/

I was reading the comments on Piotr's post and some things he said leads me to wonder if this line

extContext = ExtensionContext.createExtensionContext("com.fa.alerts", null);

might be causing/related to the problem

Hope this can help you and/or others.

Best of luck everyone!

Todd

...back to researching push notification options/viability
=D

半寸时光 2024-12-27 19:45:41

我也一直遇到你的问题。

我能够开始工作的唯一教程(经过一些更改)是在这里找到的。

http://www.adobe.com/devnet/air /articles/developing-native-extensions-air.html

我必须将 -swf-version 13 添加到 Flex 库编译器中。

我必须将 -tsa none 添加到 adt 命令中才能构建 ANE 文件。

I kept running into your problem too.

The ONLY tutorial I have been able to get to work (with some changes) has been the one found here.

http://www.adobe.com/devnet/air/articles/developing-native-extensions-air.html

I had to add -swf-version 13 to the flex library compiler.

And I had to add -tsa none to the adt command to build the ANE file.

情绪操控生活 2024-12-27 19:45:41

您是否在 FlashBuilder 中将扩展链接到 Android 平台?仅将其添加到“Flex Build Path”中的 NativeExtension 选项卡是不够的,您还必须选中中的复选框

“Flex 构建包装”>> 《谷歌Andorid》>> “本机扩展”

您也可以尝试看看差异,也许我的项目会有所帮助:
NativeAlert

Did You link the extension to the Android platform in FlashBuilder? Just adding it to the NativeExtension tab in "Flex Build Path" is not enough You also have to check the checkbox in

"Flex Build Packaging" >> "Google Andorid">> "Native Extension"

Also You can try to look at the diference and maby somthing will help from my porject:
NativeAlert

滥情空心 2024-12-27 19:45:40

快速提示,创建一个函数,
它告诉您扩展是否可用。

public static function isSupported():Boolean
{
     return extContext != null;
}

希望这有帮助。

另外,最好添加本机扩展的默认实现,它可以在操作脚本中完整编写,并在模拟器中运行应用程序时使用。

有关更多信息,请参见此处:

http://www.adobe.com/devnet /air/articles/extending-air.html

Quick tip, create a function,
which tells you whether the extension is available.

public static function isSupported():Boolean
{
     return extContext != null;
}

Hope this helps.

Also it's good to add a default implementation of the native extension, which can bee ritten entierly in actions script and will be used when you run the app in emulator.

For more information look here:

http://www.adobe.com/devnet/air/articles/extending-air.html

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