当前位置:软件学习 > Flash >>

Flash Android ANE打包之基本流程

搭建环境这里就不详细说明了

一、Android本地库编写

1.从Flash Air SDK中提取需要的jar包

Android下需要的jar包在Flash Air SDK/lib/android目录下的FlashRuntimeExtensions.jar

2.建立Android工程,加入第一步提取的jar包

3.编写与as交互的主要类Extension,Context,Function

自定义Extension类,实现FREExtension接口

自定义Context类,继承FREContext类

自定义Function类,实现FREFunction接口

Function类可以定义多个,定义之后都注册在自定义Context类的getFunctions方法中


Sample:


[java]
public class TestExtension implements FREExtension { 
    @Override 
    public FREContext createContext(String arg0) { 
        // TODO Auto-generated method stub  
        return new TestContext(); 
    } 
 
    @Override 
    public void dispose() { 
        // TODO Auto-generated method stub  
    } 
 
    @Override 
    public void initialize() { 
        // TODO Auto-generated method stub  
    } 

public class TestExtension implements FREExtension {
 @Override
 public FREContext createContext(String arg0) {
  // TODO Auto-generated method stub
  return new TestContext();
 }

 @Override
 public void dispose() {
  // TODO Auto-generated method stub
 }

 @Override
 public void initialize() {
  // TODO Auto-generated method stub
 }
}
[java]
public class TestContext extends FREContext { 
     
    @Override 
    public void dispose() { 
        // TODO Auto-generated method stub  
    } 
    @Override 
    public Map<String, FREFunction> getFunctions() { 
        HashMap<String, FREFunction> map = new HashMap<String, FREFunction>();   
        map.put("testToast", new TestToastFunction());   
        //可继续put其他function    
        return map;   
    } 

public class TestContext extends FREContext {
 
 @Override
 public void dispose() {
  // TODO Auto-generated method stub
 }
 @Override
 public Map<String, FREFunction> getFunctions() {
  HashMap<String, FREFunction> map = new HashMap<String, FREFunction>(); 
  map.put("testToast", new TestToastFunction()); 
  //可继续put其他function 
  return map; 
 }
}[java]
public class TestToastFunction implements FREFunction { 
     
    @Override 
    public FREObject call(FREContext arg0, FREObject[] arg1) { 
        FREObject msg_ = arg1[0]; 
        FREObject result=null;   
        try {   
            Toast.makeText(arg0.getActivity(), "测试成功:android本地被调用" + msg_.getAsString(), Toast.LENGTH_LONG).show();  
            result = FREObject.newObject("这是可返回的值");   
        } catch (Exception e) {   
            e.printStackTrace();   
        }   
        return result;   
    } 

public class TestToastFunction implements FREFunction {
 
 @Override
 public FREObject call(FREContext arg0, FREObject[] arg1) {
  FREObject msg_ = arg1[0];
  FREObject result=null; 
  try { 
   Toast.makeText(arg0.getActivity(), "测试成功:android本地被调用" + msg_.getAsString(), Toast.LENGTH_LONG).show();
   result = FREObject.newObject("这是可返回的值"); 
  } catch (Exception e) { 
   e.printStackTrace(); 
  } 
  return result; 
 }
}

4.把刚刚编写的工程以jar包的形式导出,命名jar包(如:HelloANENative.jar)

二、AS端

1.建立Flex库项目,选择配置为手机库

2.在项目的src目录下创建extension.xml文件,文件基本内容如下(查看更多属性):


[plain]
<extension xmlns="http://ns.adobe.com/air/extension/3.3"> 
    <id>com.adobe.ane.test</id> 
    <versionNumber>1</versionNumber> 
     
    <platforms> 
        <platform name="Android-ARM"> 
            <applicationDeployment>            
                <nativeLibrary>HelloANENative.jar</nativeLibrary><!--是之前导出的jar包--> 
                <!--即为Android本地FREExtension全路径-->   
                <SPAN style="WHITE-SPACE: pre">     </SPAN><initializer>com.cn.example.android.TestExtension</initializer>   
                <SPAN style="WHITE-SPACE: pre">     </SPAN><finalizer>com.cn.example.android.TestExtension</finalizer>                   
            </applicationDeployment>       
        </platform> 
    </platforms> 
 
</extension> 

<extension xmlns="http://ns.adobe.com/air/extension/3.3">
 <id>com.adobe.ane.test</id>
 <versionNumber>1</versionNumber>
 
 <platforms>
  <platform name="Android-ARM">
   <applicationDeployment>   
    &l

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,