利用Ant实现根据渠道号批量打包

环境准备

1.确保工程已有能正常打包的ant脚本,例如build.xml;

2.下载ant第三方库ant-contrib,支持执行循环语句,放入ant下lib目录;

下载地址:http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ 

3.由于sdk中的build.xml可能会有condition字段,但引入第三方包后会出现不支持的情况,可以参照修改:http://ant-contrib.sourceforge.net/tasks/tasks/if.html

Ant Task 定义

<taskdef resource="net/sf/antcontrib/antcontrib.properties" >           
        <classpath>              
            <pathelement location="${ant.dir}/lib/ant-contrib-1.0b3.jar" />           
        </classpath>       
    </taskdef>       
    
    <echo>Run ant-contrib-1.0b3.jar ok</echo>
    <target name="edit_and_build" >

        <echo>
Run '${channel}' apk
        </echo>

        <replaceregexp
            encoding="utf-8"
            file="AndroidManifest.xml"
            flags="s"
            match="android:name=&quot;UMENG_CHANNEL&quot;.+android:value=&quot;([^&quot;]+)&quot;"
            replace="android:name=&quot;UMENG_CHANNEL&quot; android:value=&quot;${channel}&quot;"
             />

        <property
            name="out.final.file"
            location="release/v${app_version}_${channel}.apk" />

        <antcall target="clean" />

        <antcall target="release" />
    </target>
	<target name="deploy" >
		<mkdir dir="release" />
        <foreach
            delimiter=","
            list="${market_channels}"
            param="channel"
            target="edit_and_build" >
        </foreach>
    </target>

 local.properties修改

ant.dir=D:/Tools/apache-ant-1.9.5
market_channels=360助手,应用宝,豌豆荚,安智市场
app_version=2.2

执行构建命令,触发批量构建:

ant deploy

问题

1.properties文件中文显示问题?

可以通过安装eclipse插件properties editor解决;

猜你喜欢

转载自markjoker.iteye.com/blog/2235559