如何构建 Ant 脚本来输出 swfs 与 air 包,并在编译过程中根据我想要的目标使用不同的类?
例如,我正在构建一个适用于网络、移动和桌面的应用程序。在某些情况下,我的类将使用仅限 AIR 的组件。我希望能够创建 ANT 构建脚本,在为 Web 输出 swf 时不包含这些类。我该如何去做呢?
最佳答案
以下是我针对类似情况所做的操作:
<target name="define.compile.task" depends="initflex">
<presetdef name="flex.build">
<mxmlc file="${src.dir}/${src.file.path}"
output="${output.dir}/${output.file.path}" ...>
<compiler.source-path path-element="${src.dir}"/>
...
</mxmlc>
</presetdef>
</target>
<target name="parametrized.web.build" depends="define.compile.task">
<flex.build>
<compiler.define name="CONFIG::AllowAirComponents" value="false" />
</flex.build>
</target>
<target name="parametrized.air.build" depends="define.compile.task">
<flex.build configname="airmobile">
<compiler.define name="CONFIG::AllowAirComponents" value="true" />
</flex.build>
</target>
然后,我可以定义目标,例如
<target name="buildwebclass1">
<antcall target="parametrized.web.build">
<param name="src.file.path" value="path/to/MyClass.as"/>
<param name="output.file.path" value="MyClass.swf"/>
</antcall>
</target>
或者:
<target name="buildairclass1">
<antcall target="parametrized.air.build">
<param name="src.file.path" value="path/to/MyAirClass.as"/>
<param name="output.file.path" value="MyAirClass.swf"/>
</antcall>
<exec executable="${FLEX_HOME}/bin/adt" failonerror="true">
... (adt arguments)
</exec>
</target>
如果我有一些通用代码工厂,仅在必要时实例化空气类,我会用 CONFIG::AllowAirComponents { ... }
包装它,这样我的 AIR 特定类就不会干扰网络构建。
希望这有帮助!
关于flash - 如何构建 Ant 脚本以根据我的目标输出进行不同的编译。 AIR 与 SWF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7865442/