如何编写android ANE

1.编写AndroidAne.jar:

a.编写SkyContext.java:

import java.util.HashMap;
import java.util.Map;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;

public class SkyContext extends FREContext{

    @Override
    public void dispose() {}
    @Override
    public Map<String, FREFunction> getFunctions() {
        HashMap<String, FREFunction> map = new HashMap<String, FREFunction>();
        map.put("testFunction", new TestToastFunction());
        //可继续put其他function
        return map;
    }

}

 

b.编写SkyExtension.java:

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

public class SkyExtension implements FREExtension{
    @Override
    public FREContext createContext(String pType) {
        return new SkyContext();
    }
    @Override
    public void dispose() {}
    @Override
    public void initialize() {}
}

c.编写TestToastFunction.java:

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
//import android.widget.Toast;

public class TestToastFunction implements FREFunction{
    @Override
    public FREObject call(FREContext context, FREObject[] params) {
        return null;
    }

}

 

2.编写AndroidAne.ane:

a.编写extension.xml:

<?xml version="1.0" encoding="UTF-8"?>
<extension xmlns="http://ns.adobe.com/air/extension/3.7">
    <id>extTest</id>
    <versionNumber>1</versionNumber>
    <platforms>
        <platform name="Android-ARM">
            <applicationDeployment>
                <!--即为Android本地导出的jar包名-->
                <nativeLibrary>AndroidAne.jar</nativeLibrary>
                <!--即为Android本地FREExtension全路径-->
                <initializer>SkyExtension</initializer>
                <finalizer>SkyExtension</finalizer>
            </applicationDeployment>
         </platform>
    </platforms>
</extension>

 

b.编写HelloWorldExtension.as:

package
{
    import flash.external.ExtensionContext;
    public class HelloWorldExtension
    {
        public static const KEY:String = "testFunction";
        public static const EXTENSION_ID:String = "extTest";
        private var extContext:ExtensionContext;
        public function HelloWorldExtension()
        {
            extContext = ExtensionContext.createExtensionContext(EXTENSION_ID,"");
        }
        public function hello(name:String):String{
            if(extContext){
                return extContext.call(KEY,name) as String;
            }
            return "mlgb";
        }
    }
}

 

c.生成swc:

acompc -compiler.debug=false -external-library-path+=D:/FlexSDK/frameworks/libs/framework.swc  -swf-version=20 -compiler.source-path ./src \
    -include-sources ./src -output AndroidAne.swc

从AndroidAne.swc解压出library.swf

d.生成ANE:

adt -package -target ane AndroidAne.ane extension.xml  -swc AndroidAne.swc -platform Android-ARM library.swf AndroidAne.jar

 

3.在工程中引用AndroidAne.ane即可

var tt : HelloWorldExtension = new HelloWorldExtension;

trace(tt.hello("why"));

如何编写android ANE,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。