Ant编译Flex

Flash Buider编译Flex项目很慢,卡死。实在不敢恭维。工作的原因,要使用Ant编译,无奈,Adobe官方脑残的帮助文档,关于Ant的介绍简直就是鸡肋,实在让人愤慨。

 

 

准备:

  1. flexsdk(4.6) 下载地址http://www.adobe.com/devnet/flex/flex-sdk-download.html
  2. java  jdk (1.6以上)
  3. ant apache-ant-1.9.4 下载地址 http://ant.apache.org/
  4. ant-contrib (为什么需要这个,我还没仔细追究) 下载地址 http://sourceforge.net/projects/ant-contrib/

第一步,安装JDK,设置JAVA_HOME环境变量,安装路径自己根据实际情况

第二步,解压flexsdk,d:\flexsdk4.6\bin 此目录结构即可

第三步,解压ant d:\apache-ant-1.9.4\bin 此目录结构即可

第四步,解压ant-contrib,目录结构为 docs,lib,ant-contrib-1.03b3.jar,将lib目录中所有jar文件和ant-contrib-1.03b3.jar拷贝放到 d:\apache-ant-1.9.4\lib目录中

第五步,进入d:\flexsdk4.6\lib目录,将所有jar包拷贝,放到d:\apache-ant-1.9.4\lib中,可避免编译过程中出现的[mxmlc] 错误: PermGen space ,进入d:\flexsdk4.6\ant\lib目录,拷贝flexTask.jar到d:\apache-ant-1.9.4\lib,否则无法编译。

 

flexsdk各文件夹作用解释

  • ant\ ant编译flex的源码和jar文件,用户可根据自己需要重写代码并生成jar包。
  • asdoc\ 文档
  • bin\ 编译工具
  • framework\ flex框架,css样式,编译默认配置文件
  • include\ 不知何用
  • install \貌似是安卓的调试驱动
  • lib \ 不多赘述
  • runtimes\
  • samples\ 样式
  • templates\编译模板(坑爹的迷惑。。。。因为mxmlc根本不从这里拿模板,模板在flexTask.jar包里)
<?xml version="1.0" encoding="UTF-8" ?>
<project name="DSViewCIRSys" basedir=".">
	<!-- 定义ant存放位置 -->
	<property name="ant.lib.dir" value="D:\apache-ant-1.9.4\lib" />
	<!-- 定义Flex SDK存放位置 -->
	<property name="FLEX_HOME" value="D:\flexsdk4.6\" />

	<!-- 初始化时间格式,以便使用 -->
	<tstamp>
		<format property="TODAY" pattern="yy.mm.dd" />
	</tstamp>

	<!-- 导入ant支持包 -->
	<path id="ant.classpath">
		<fileset dir="${ant.lib.dir}">
			<include name="*.jar" />
		</fileset>
	</path>
	<!-- 定义目标编译结果路径 -->
	<property name="dist.home" value="./dist" />
	<property name="dist.home.src" value="./dist/src" />
	<property name="dist.home.libs" value="./dist/libs" />
	<property name="dist.home.bin" value="./dist/bin" />
	<!--<property name="dist.home.assets" value="./dist/assets" />-->

	<!-- 定义源码路径 -->
	<property name="project.home" value="./" />
	<property name="project.home.src" value="./src" />
	<property name="project.home.libs" value="./libs" />
	<!--<property name="project.home.assets" value="./assets" />-->
	
	<property name="release.system" value="./dist/release/system"/>
	<property name="release.custom" value="./dist/release/custom"/>
	<property name="release.user" value="./dist/release/user"/>

<target name="build">
     <antcall target="init"/>
     <antcall target="confusion"/>
     <antcall target="compileFP"/>
     <antcall target="wrapper"/>
	 <antcall target="moveConfigXml"/>
	 <antcall target="copy3"/>
</target>


	<!-- =================================================================== -->
	<!-- 初始化 -->
	<!-- 清除dist目录; 将源码复制过去. -->
	<!-- =================================================================== -->
	<target name="init">
		<taskdef resource="flexTasks.tasks" classpathref="ant.classpath" />
<!-- 		<taskdef resource="confusion.tasks" classpathref="ant.classpath" /> -->
		<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="ant.classpath" />
		<echo message="Flex SDK Home: ${FLEX_HOME}" />
		<delete dir="${dist.home}" />
		<mkdir dir="${dist.home}" />
		<mkdir dir="${release.system}" />
		<mkdir dir="${release.custom}" />
		<mkdir dir="${release.user}" />
		<copy todir="${dist.home.src}">
			<fileset dir="${project.home.src}" />
		</copy>

		<copy todir="${dist.home.libs}">
			<fileset dir="${project.home.libs}" />
		</copy>
		<!--<copy todir="${dist.home.assets}">
					<fileset dir="${project.home.assets}" />
		</copy>-->
	</target>

	<!-- =================================================================== -->
	<!-- 混淆代码 -->
	<!-- =================================================================== -->
	<target name="confusion" depends="init">
		<echo message="star confusion code..." />
	<!--	<for param="file">
			<path>
				<fileset dir="${dist.home.src}">
					<include name="**/*.as" />
				</fileset>
			</path>
			<sequential>
				<confusion fileName="@{file}" />
				<echo message="@{file} is confusioned!!" />
			</sequential>
		</for>-->
	</target>
	
	<!-- =================================================================== -->
	<!-- 编译Flex Project 项目 -->
	<!-- =================================================================== -->
	<target name="compileFP" depends="confusion">
		<echo message="start compile Flex Project..." />
		<for param="file">
			<path>
				<fileset dir="${dist.home.src}">
					<include name="**/*.mxml" />
				</fileset>
			</path>
			<sequential>
				<!-- 通过正则表达式取出modules中的模块文件,进行批量编译~! -->
				<propertyregex override="yes" property="compile.target.name"
					input="@{file}" regexp="(.*)src(.*)(mxml)" replace="\1bin\2swf" />
				<mxmlc warnings="false"  file="@{file}" output="${compile.target.name}" debug="false"
					incremental="true">
					<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
					<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
					<show-actionscript-warnings>false</show-actionscript-warnings>
					 <show-binding-warnings>false</show-binding-warnings>
					<source-path path-element="${dist.home.src}" />
					<!--<source-path path-element="${dist.home.assets}" />-->
					<include-libraries file="${dist.home.libs}" />  
				</mxmlc>
				<!-- 清除缓存文件 -->
				<delete file="${compile.target.name}.cache" />
				<echo message="Compiled @{file} =====>>   ${compile.target.name}" />
				<echo message=" " />
			</sequential>
		</for>
	</target>
	 
	<target name="wrapper" >
	<taskdef name="html-wrapper" classname="flex.ant.HtmlWrapperTask"  classpath="${ant.lib.dir}/flexTasks.jar" />
    <html-wrapper  output="${basedir}\dist\release\system" swf="Index" history="true"  height="100%"	width="100%" title="大话西游" bgcolor="white"   />
	<html-wrapper  output="${basedir}\dist\release\custom" swf="Index" history="true"  height="100%"	width="100%" title="" bgcolor="white"   />
	<html-wrapper  output="${basedir}\dist\release\user" swf="Index" history="true"  height="100%"	width="100%" title="" bgcolor="white"   />
	<echo message="Generate HTML OK" />
  </target>
  <target name="moveConfigXml">
	<copy todir="${dist.home}/bin">
			<fileset dir="${project.home.src}" >
			<include name="Config.xml"/>
	</fileset>
	</copy>
  </target>
  <target name="copy3">
	<copy todir="${release.system}">
			<fileset dir="${dist.home.bin}" >
			</fileset>
	</copy>
		<copy todir="${release.custom}">
			<fileset dir="${dist.home.bin}" >
			</fileset>
	</copy>
		<copy todir="${release.user}">
			<fileset dir="${dist.home.bin}" >
			</fileset>
	</copy>
	<echo message="Copy 3 Success" />
  </target>
</project>

 以上是我们工程需要而配置。个别工程,自行改动。

 

 

 

 

你可能感兴趣的:(ant编译)