專案建立請參照:[ANE]開發Adobe Air ANE - Part 1:使用Android Studio
1.先於專案程式碼目錄建立以下檔案
MyAneExtension.java
package extension.myfirstandroidane;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
public class MyAneExtension implements FREExtension{
@Override
public void initialize() {
}
@Override
public FREContext createContext(String s) {
return new MyAneExtensionContext();
}
@Override
public void dispose() {
}
}
MyAneExtensionContext.java
package extension.myfirstandroidane;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import java.util.HashMap;
import java.util.Map;
public class MyAneExtensionContext extends FREContext {
@Override
public Map<String, FREFunction> getFunctions() {
Map<String, FREFunction> functions = new HashMap<String, FREFunction>();
functions.put("alertDialog", new AlertFREFunction());
return functions;
}
@Override
public void dispose() {
}
}
AlertFREFunction.java
package extension.myfirstandroidane;
import android.app.AlertDialog;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
public class AlertFREFunction implements FREFunction {
@Override
public FREObject call(FREContext freContext, FREObject[] freObjects) {
String title = "title";
String alertMessage = "alertMessage";
String buttonLabel = "ok";
try {
alertMessage = freObjects[0].getAsString();
title = freObjects[1].getAsString();
} catch (Exception e) {
}
new AlertDialog.Builder(freContext.getActivity())
.setTitle(title)
.setMessage(alertMessage)
.setPositiveButton(buttonLabel,null).show();
return null;
}
}
2.建立Action Script3.0 專案
AndroidAlert.as
package zpl.extension
{
import flash.events.StatusEvent;
import flash.external.ExtensionContext;
public class AndroidAlert
{
private static var _instance:AndroidAlert;
public static function get instance():AndroidAlert
{
if(_instance == null)
{
_instance = new AndroidAlert();
}
return _instance;
}
private var _extension:ExtensionContext;
public function AndroidAlert()
{
_extension = ExtensionContext.createExtensionContext( "zpl.ane.alert", "" );
}
public function show(msg:String,title:String):void
{
_extension.call("alertDialog",msg,title);
}
}
}
3.建立extension設定檔
extension.xml
<extension xmlns="http://ns.adobe.com/air/extension/21.0">
<id>zpl.ane.alert</id>
<versionNumber>1.0.0</versionNumber>
<platforms>
<platform name="Android-ARM">
<applicationDeployment>
<nativeLibrary>classes.jar</nativeLibrary>
<initializer>extension.myfirstandroidane.MyAneExtension</initializer>
<finalizer>extension.myfirstandroidane.MyAneExtension</finalizer>
</applicationDeployment>
</platform>
<platform name="default">
<applicationDeployment/>
</platform>
</platforms>
</extension>
4.使用compc生成swc
compc指令參考
compc -optimize -source-path ../src -include-sources ../src -external-library-path "xxx\ascsdk\21.0.0\frameworks\libs\air" -output "AndrodAlert.swc"
5.將swc解壓縮後可取得 library.swf
6.使用 ADT 建立ANE
ADT 指令參考
adt -package -target ane AndrodAlert.ane extension.xml -swc AndrodAlert.swc -platform Android-ARM library.swf classes.jar -platform default library.swf
7.輸出 AndrodAlert.ane 完成
※步驟3~7可使用 輸出ANE用bat檔 代替
如需由Java層呼叫AS3請參考:
[ANE]開發Adobe Air ANE - Part 3:FREContext dispatchStatusEventAsync
請問 extension.xml 檔案放在哪個位置有差別嗎?
回覆刪除應該是沒有差別的.
刪除但為了方便設定路徑,
建議還是放在同目錄底下.