自定义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" failοnerrοr="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" failοnerrοr="false"  overwrite="true">
            <fileset dir="${env.QUICK_V3_ROOT}/quick/cocos" includes="**"/>
        </copy>
    		
        <copy todir="src/framework" failοnerrοr="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}" failοnerrοr="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" failοnerrοr="false"/>
        <delete  dir="target/res" failοnerrοr="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" failοnerrοr="false"  overwrite="true">
            <fileset dir="${env.QUICK_V3_ROOT}/quick/cocos" includes="**"/>
        </copy>
            
        <copy todir="src/framework" failοnerrοr="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}" failοnerrοr="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" failοnerrοr="false"/>
        <delete  dir="target/res" failοnerrοr="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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值