Adobe AIR 2 可以使用系统命令行了,用到了新的API:NativeProcess,请用Flash Builder 4去编译,项目使用SDK 4。We can use AIR2 to call system command line. It is the NativeProcess. Please use Flash Builder 4 to compile with flex SDK 4.
我想用AIR开发一个执行命令行的工具。在这儿找到一个不错的例子。I need a AIR Application it could execute command line. I find a good example.
http://www.flexpasta.com/index.php/2009/12/01/command-line-execution-in-air-20/
老外用起来没问题,但处理中文会乱码。一开始我就怀疑writeUTFBytes这个方法有问题,因为不能设置编码,但一直没想到解决办法。
之后在这儿找到正解http://bbs.airia.cn/FLEX/thread-8130-1-1.aspx
看来writeMultiByte和readMultiByte是处理非英文字符的正确方式。 Because My system language is simplified Chinese. I need to specify the “charSet”。
所以最终的文件就改成这样了:
TestCMD.mxml (主程序)
TestCMD-app.xml (配置文件)
Warning:
- 配置文件保证第一行中的namespace必须是2.0beta。Make sure the line 1 in the Application configuration file
<application xmlns="http://ns.adobe.com/air/application/2.0beta">
- 还要加上一行。Need to add this.
<supportedProfiles>extendedDesktop</supportedProfiles>
加上extendedDesktop才能开启这个扩展功能。
很多文章都说要加这个标签,但它真的管用么?在发布时,会报错:
The English Error Version is :
Error creating AIR file: my-app.xml: error 306: Descriptor must support the profile desktop, mobileDevice, or extendedMobileDevice
Yes! The "extendedDesktop " is correct. But what’s wrong?
Some people say:
http://www.video-flash.de/index/nativeprocess-anwendungen-starten-air/comment-page-1/
http://forums.adobe.com/thread/532531?tstart=30
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Label text="{NativeProcess.isSupported}"/>
</mx:WindowedApplication>
If you use ‘extendedDesktop desktop’. You could export your project, but the application can’t use NativeProcess API.
Test by yourself. The result is "false".
看看大家的讨论:
http://forums.adobe.com/thread/532531?tstart=0
How to release My App?如何才能发布程序?
配置文件一定要写这一行
<supportedProfiles>extendedDesktop</supportedProfiles>
We should use adt.exe to package.最终打包程序要用adt.exe。参考官方文档:
http://help.adobe.com/en_US/air/build/WS789ea67d3e73a8b22388411123785d839c-8000.html
http://help.adobe.com/en_US/air/build/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff1.html#WS789ea67d3e73a8b2383e9229123db8f19fd-8000

目前AIR 2的文档奇缺,当然都在不断完善中,还有很多BUG。这个事很囧啊,大费周折,打包还得用命令行。
Show you my command:
adt -package -storetype pkcs12 -keystore E:\work\lukialee\docs\mee\airApp.p12 -target native myApp.air TestNP2-app.xml .
The key is :"-target native".
必须在命令中使用这个参数,才能正确地打包。具体原因我是不想再讲了,我折腾两天了,试过无数方法了……