自定义build.xml使用ANT打包

前端之家收集整理的这篇文章主要介绍了自定义build.xml使用ANT打包前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

以前多渠道自动打包都是用批处理命令,写出来的批处理又臭又长。后来看有个师兄用ANT,发现真的是打包神奇。另外还有gradle更高级些,这个还没仔细研究。

下面贴一个支持Windows和Mac双系统的打包脚本,注意,这个脚本并没有编译Android项目,只是演示一下复制和压缩操作,还有对不同操作系统的识别和处理。大家用的到的可以借鉴下。

<?xml version="1.0" encoding="UTF-8"?>
<project name="make_target_zip" default="compile">
    	
    <!-- first create our properties -->
    <condition property="isWindows">
        <os family="windows" />
    </condition>
    
    <condition property="isMac">
        <os family="mac" />
    </condition>
    	
    <property name="zip_name" value="target/GameContent.zip" />
    
    <mkdir dir="target" />
    <copy todir="target/res/res" failonerror="false"  overwrite="true">
        <fileset dir="res" includes="**"/>
    </copy>
    
    <target	 name="compile_windows" if="isWindows">
				
        <property environment="env" />
        <condition property="sdk.dir" value="${env.QUICK_V3_ROOT}">
            <isset property="env.QUICK_V3_ROOT" />
        </condition>
    		
        <copy todir="src/cocos" failonerror="false"  overwrite="true">
            <fileset dir="${env.QUICK_V3_ROOT}/quick/cocos" includes="**"/>
        </copy>
    		
        <copy todir="src/framework" failonerror="false"  overwrite="true">
            <fileset dir="${env.QUICK_V3_ROOT}/quick/framework" includes="**"/>
        </copy>
    										    	
        <exec executable="${env.QUICK_V3_ROOT}/quick/bin/compile_scripts.bat"> 
            <arg line="-i src -o target/game.zip"/> 
        </exec>    		
    	
        <delete file="${zip_name}" failonerror="false"/>
        <zip destfile="${zip_name}">
            <fileset dir="" includes="config.json"/>
            <fileset dir="target" includes="game.zip"/>
            <zipfileset dir="target/res"/>
            <!--<zipfileset dir="scripts" prefix="src"/>-->
        </zip>
        
        <delete  file="target/game.zip" failonerror="false"/>
        <delete  dir="target/res" failonerror="false" quiet="true" />
    </target>
    
    <target	 name="compile_mac" if="isMac">
                
        <property environment="env" />
        <condition property="sdk.dir" value="${env.QUICK_V3_ROOT}">
            <isset property="env.QUICK_V3_ROOT" />
        </condition>
            
        <copy todir="src/cocos" failonerror="false"  overwrite="true">
            <fileset dir="${env.QUICK_V3_ROOT}/quick/cocos" includes="**"/>
        </copy>
            
        <copy todir="src/framework" failonerror="false"  overwrite="true">
            <fileset dir="${env.QUICK_V3_ROOT}/quick/framework" includes="**"/>
        </copy>
                                                    
        <exec executable="/bin/sh"> 
            <arg value="-c"/>
            <arg value="${env.QUICK_V3_ROOT}/quick/bin/compile_scripts.sh -i src -o target/game.zip"/> 
        </exec>
        
        <delete file="${zip_name}" failonerror="false"/>
        <zip destfile="${zip_name}">
            <fileset dir="" includes="config.json"/>
            <fileset dir="target" includes="game.zip"/>
            <zipfileset dir="target/res"/>
            <!--<zipfileset dir="scripts" prefix="src"/>-->
        </zip>
        
        <delete  file="target/game.zip" failonerror="false"/>
        <delete  dir="target/res" failonerror="false" quiet="true" />
    </target>
    
    <!-- run everything from our main target -->
    <!-- the other targets will only be run when their properties are true -->
    <target name="compile" depends="compile_windows,compile_mac">
        <echo message="Running Compile target" />
        <echo message="os.name = ${os.name}" />
        <echo message="os.arch = ${os.arch}" />
        <echo message="os.version = ${os.version}" />
    </target>
    
</project>

猜你在找的XML相关文章