加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

自定义build.xml使用ANT打包

发布时间:2020-12-16 02:24:23 所属栏目:百科 来源:网络整理
导读:以前多渠道自动打包都是用批处理命令,写出来的批处理又臭又长。后来看有个师兄用ANT,发现真的是打包神奇。另外还有gradle更高级些,这个还没仔细研究。 下面贴一个支持Windows和Mac双系统的打包脚本,注意,这个脚本并没有编译Android项目,只是演示一下复

以前多渠道自动打包都是用批处理命令,写出来的批处理又臭又长。后来看有个师兄用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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读