如何借助 Adobe AIR 中的 NativeProcess 通过 Adt.jar 构建 .air 文件? [英] How to build .air file through Adt.jar with the help of NativeProcess in Adobe AIR?
问题描述
<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
</fx:Declarations>
<fx:Script>
<![CDATA[
private var nativeProcess:NativeProcess;
private function onGo() : void {
outputField.text = "";
var file:File = new File("C:\\Program Files (x86)\\Java\\jdk1.6.0_18\\bin\\java.exe");
var descriptorFile:File = new File("C:\\AirPackageApp-app.xml");
var swfFile:File = new File("C:\\AirPackageApp.swf");
var processArgs:Vector.<String> = new Vector.<String>;
processArgs.push("-jar");
processArgs.push("C:\\adt.jar");
processArgs.push("-checkstore");
processArgs.push("-storetype");
processArgs.push("pkcs12");
processArgs.push("-keystore");
processArgs.push("-storepass");
processArgs.push("sybrant");
processArgs.push("c:\\nodename.air");
processArgs.push(descriptorFile.nativePath);
processArgs.push(swfFile.nativePath);
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.arguments = processArgs;
nativeProcessStartupInfo.executable = file;
nativeProcess = new NativeProcess();
nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA,onCertErrOutputData);
nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,onCertOutputData);
nativeProcess.start(nativeProcessStartupInfo);
}
private function onCertErrOutputData(event:ProgressEvent) : void {
var certResponse:String = new String();
certResponse = nativeProcess.standardError.readUTFBytes(nativeProcess.standardError.bytesAvailable);
trace(certResponse);
outputField.text += certResponse;
if ( certResponse.substr(0,5) == "valid") {
trace("Correct password!");
nativeProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA,onCertOutputData);
nativeProcess.exit();
} else {
trace("Incorrect password! Error...");
nativeProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA,onCertOutputData);
nativeProcess.exit();
}
}
protected function onCertOutputData(event:ProgressEvent):void
{
trace(nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable));
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Button label="go" click="onGo()" />
<s:TextInput id="passField"/>
<s:TextArea id="outputField" width="100%" height="100%"/>
它在使用命令提示符时一切正常.它在 C:\nodename.air 中生成 nodename.air 文件.但是当使用本机进程时,它可以使用以下参数
It works everything fine when working with command prompt.It generate nodename.air file in C:\nodename.air. But when using native process it works upto following arguments
processArgs.push("-storepass");
processArgs.push("sybrant");
之后,如果我拼错了我的 air-descriptor.xml 文件或我的 swf 文件,它不会抛出任何错误消息,但会在命令提示符中抛出错误.(操作系统 Windows 7,Java 版本 1.6)
After that if i missspelled my air-descriptor.xml file or my swf file it doesn't throw any error msg but it throws error in command prompt.(OS Windows 7, Java version 1.6)
谢谢,拉贾.J
推荐答案
试试这个
这门课可能对你有帮助air_command.batjava -jar adt.jar -package -storetype pkcs12 -keystore keyfile.p12 -storepass mypassword SampleApp.air SampleApp-app.xml SampleApp.swf
This class might helpful for you air_command.bat java -jar adt.jar -package -storetype pkcs12 -keystore keyfile.p12 -storepass mypassword SampleApp.air SampleApp-app.xml SampleApp.swf
运行应用程序之前
- 确保设置了 java 类路径
- 桌面扩展桌面移动设备扩展移动设备
到
扩展桌面
package
{
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.ProgressEvent;
import flash.filesystem.File;
import mx.controls.Alert;
public class PlatformPackaging
{
private var nativeProcess:NativeProcess;
private var isErrorOccured:Boolean;
private var batFile:File;
private var cmdFile:File;
private function get isWindows():Boolean
{
return true;
}
public function PlatformPackaging()
{
}
public function start(targetPlatform:String):void
{
if(isWindows)
{
if(targetPlatform == TargetPlatform.APPLE_IPA)
{
batFile = File.applicationDirectory.resolvePath("publish/ipa_command.bat");
cmdFile = new File("c:\\Windows\\System32\\cmd.exe");
}
else if(targetPlatform == TargetPlatform.WINDOWS_AIR)
{
batFile = File.applicationDirectory.resolvePath("publish/air_command.bat");
cmdFile = new File("c:\\Windows\\System32\\cmd.exe");
}
else if(targetPlatform == TargetPlatform.ANDROID_APK)
{
batFile = File.applicationDirectory.resolvePath("publish/apk_command.bat");
cmdFile = new File("c:\\Windows\\System32\\cmd.exe");
}
}
proceedToPackaging();
}
private function proceedToPackaging():void {
var processArgs:Vector.<String> = new Vector.<String>;
processArgs.push("/c");
processArgs.push(batFile.nativePath);
var workingDirectory:File = File.applicationDirectory.resolvePath("publish/");
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.arguments = processArgs;
nativeProcessStartupInfo.executable = cmdFile;
nativeProcessStartupInfo.workingDirectory = workingDirectory;
nativeProcess = new NativeProcess();
nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA,onStandardErrorOutputDataHandler);
nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,onStandardOutputDataHandler);
nativeProcess.start(nativeProcessStartupInfo);
}
private function onStandardErrorOutputDataHandler(event:ProgressEvent) : void
{
var certResponse:String = nativeProcess.standardError.readUTFBytes(nativeProcess.standardError.bytesAvailable);
trace(certResponse);
nativeProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA,onStandardOutputDataHandler);
nativeProcess.exit();
}
Alert.show(certResponse,'Error');
}
protected function onStandardOutputDataHandler(event:ProgressEvent):void
{
var status:String = nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);
Alert.show(status)
}
}
}
这篇关于如何借助 Adobe AIR 中的 NativeProcess 通过 Adt.jar 构建 .air 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!