使用RSL发布flex项目需要的build.xml要诀详解

Silver 撰写  

遇到了一个ANT编译后不能正常发布使用的问题,于是花了两天(人比较呆)去研究,研究得这么辛苦,当然要把心得写下来,对于ADOBE貌似详细,但语蔫不详的文档作风很是失望!
在此感谢此文作者:http://www.kahunaburger.com/2009/04/08/flash-player-verifyerror-error-1014-with-rsls/
给了我解决问题的思路

要是用flash build 4.1自带的flex 4.1的sdk的flex-config.xml记得更新里面的默认编译FP版本为10.1,否则还是10.0的

build.properties文件

#Flex SDK 路径
FLEX_HOME=G:\\flexsdk
#根目录
APP_ROOT=G:\\riasource\\0.trunk
#ANT 安装目录
ANT_HOME=D:\\tools\\apache-ant-1.8.0
#本地部署目录(wamp/www)
DEPLOY_DIR=E:/wamp/www/ihaveu2

build.xml文件

<?xml version="1.0" encoding="utf-8"?>
<project name="Task Build Main Script" default="build" basedir=".">
	<!-- 加载全局properties -->
	<property file="../build.properties" />
	<!-- 源文件路径 -->
	<property name="SRC_DIR" value="${basedir}/srcs" />
	<!-- assets路径 -->
	<property name="ASSETS_DIR" value="${basedir}/assets" />
	<!-- config路径-->
	<property name="CONFIG_DIR" value="${APP_ROOT}/main/config/locale" />
	<!-- 引入flexTasks.jar -->
	<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
	<taskdef resource="net/sf/antcontrib/antlib.xml">
		<classpath>
			<pathelement location="${ANT_HOME}/lib/ant-contrib-1.0b3" />
		</classpath>
	</taskdef>

	<!-- 优化和生成项目需要用到的RSL -->
	<target name="createRSL">
		<macrodef name="optimize-rsl">
			<attribute name="rsl-dir" />
			<attribute name="swc-dir" />
			<attribute name="swc-name" />
			<sequential>
				<unzip src="@{swc-dir}/@{swc-name}.swc" dest="@{rsl-dir}">
					<patternset>
						<include name="library.swf" />
					</patternset>
				</unzip>
				<java jar="${FLEX_HOME}/lib/optimizer.jar" fork="true" failonerror="true">
					<jvmarg line="-ea -DAS3 -DAVMPLUS -Dflexlib=${FLEX_HOME}/frameworks -Xms32m -Xmx384m -Dsun.io.useCanonCaches=false" />
					<arg line="'@{rsl-dir}/library.swf' --output '@{rsl-dir}/@{swc-name}.swf' --keep-as3-metadata='Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient,RemoteClass' " />
				</java>
				<delete file="@{rsl-dir}/library.swf" />
				<java jar="${FLEX_HOME}/lib/digest.jar" fork="true" failonerror="true">
					<jvmarg line="-ea -DAS3 -DAVMPLUS -Xms32m -Xmx384m -Dsun.io.useCanonCaches=false" />
					<arg line="--digest.rsl-file  @{rsl-dir}/@{swc-name}.swf --digest.swc-path  @{swc-dir}/@{swc-name}.swc" />
				</java>
			</sequential>
		</macrodef>		

		<!--把项目依赖的swc变成我们需要的RSL文件-->
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/library/bins" swc-name="ihaveuLib_magazine" />
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/library/bins" swc-name="ihaveuLib_main" />
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/referenceLibs/bins" swc-name="PureMVC_AS3_MultiCore_1_0_5" />
		<optimize-rsl rsl-dir="${DEPLOY_DIR}" swc-dir="${APP_ROOT}/referenceLibs/bins" swc-name="TweenLite" />
	</target>

	<!-- 构建web项目  -->
	<target name="build" depends="createRSL" >
		<exec executable="svnversion" outputproperty="revisionVersion" />
		<copy todir="${DEPLOY_DIR}">
			<fileset dir="${SRC_DIR}/web_runtime">
				<include name="**/**" />
			</fileset>
		</copy>

		<copy todir="${DEPLOY_DIR}/assets">
			<fileset dir="${ASSETS_DIR}/web_runtime">
				<include name="**/**" />
			</fileset>
			<!--
			<fileset dir="${ASSETS_DIR}/air_runtime">
				<include name="**/**" />
			</fileset>
			-->
		</copy>

		<mxmlc file="${DEPLOY_DIR}/index.mxml">
			<!-- 方便可以进行远程debug -->
			<debug>true</debug>
			<!-- 项目需要用到的locale名字,其中在SDK 4.1 里面framework locale目录zh_tw已经改成zh_TW,但千万别信,使用的时候还是要写成zh_tw -->
			<locale>en_US</locale>
			<locale>zh_CN</locale>
			<locale>zh_tw</locale>
			<!--项目的多语言及配置文件目录-->
			<source-path path-element="${CONFIG_DIR}/en_US" />
			<source-path path-element="${CONFIG_DIR}/zh_CN" />
			<source-path path-element="${CONFIG_DIR}/zh_tw" />
			<!-- 依赖的flex 4.1框架的RSL, 注意:顺序不能乱!若不写这一段则会报错:VerifyError: Error #1014: 无法找到类 。估计是由于下面自己定义的RSL依赖次序被优先了 -->
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/framework_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="framework_4.1.0.16076.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/textLayout.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/tlf/1.1.0.604/textLayout_1.1.0.604.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="textLayout_1.1.0.604.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="libs/osmf.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/osmf_flex.4.0.0.13495.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="osmf_flex.4.0.0.13495.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/spark.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/spark_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="spark_4.1.0.16076.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/sparkskins.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/sparkskins_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="sparkskins_4.1.0.16076.swz"/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/rpc.swc">
				<url rsl-url="http://fpdownload.adobe.com/pub/swz/flex/4.1.0.16076/rpc_4.1.0.16076.swz" policy-file-url="http://fpdownload.adobe.com/pub/swz/crossdomain.xml"/>
				<url rsl-url="rpc_4.1.0.16076.swz" />
			</runtime-shared-library-path>
			<!-- 依赖的第三方RSL, 如果有依赖关系,则应该按照依赖次序 进行定义-->
			<runtime-shared-library-path path-element="${APP_ROOT}/referenceLibs/bins/PureMVC_AS3_MultiCore_1_0_5.swc">
				<url rsl-url="PureMVC_AS3_MultiCore_1_0_5.swf" policy-file-url=""/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${APP_ROOT}/referenceLibs/bins/TweenLite.swc">
				<url rsl-url="TweenLite.swf" policy-file-url=""/>
			</runtime-shared-library-path>		

			<runtime-shared-library-path path-element="${APP_ROOT}/library/bins/ihaveuLib_main.swc">
				<url rsl-url="ihaveuLib_main.swf" policy-file-url=""/>
			</runtime-shared-library-path>
			<runtime-shared-library-path path-element="${APP_ROOT}/library/bins/ihaveuLib_magazine.swc">
				<url rsl-url="ihaveuLib_magazine.swf" policy-file-url=""/>
			</runtime-shared-library-path>
			<!-- 指定哪些包是不需要编译进输出的swf, 不写这段会把框架打包进index.swf里面去 -->
			<external-library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
				<include name="*.swc" />
				<include name="air/*.swc" />
			</external-library-path>
		</mxmlc>
	</target>
</project>

发表评论

你必须在 登录 后才能发表评论.