How to build .air file through Adt.jar with the help of NativeProcess in Adobe AIR?


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

Before run applications

* make sure java class path is set
* <supportedProfiles>desktop extendedDesktop mobileDevice exendedMobileDevice</supportedProfiles>

to

<supportedProfiles>extendedDesktop</supportedProfiles></pre>
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);

 isErrorOccured = true;

 if ( certResponse.substr(0,5) == "valid") {
 trace("Correct password!");
 nativeProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA,onStandardOutputDataHandler);
 nativeProcess.exit();
 } else {
 trace("Incorrect password! Error...");
 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);

 if(isErrorOccured == false)
 Alert.show(status)
 }
 }
Advertisements

One thought on “How to build .air file through Adt.jar with the help of NativeProcess in Adobe AIR?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s