Android 自动编译、打包生成apk文件 4 - 多渠道批量打包
相关文章列表:
当前描述多渠道批量打包是基于第3篇文章基础之上的打包方式。
批量按渠道打包要做几件事情:
1. 存储渠道号
2. 取出渠道号
3. 遍历渠道号执行4,5操作
4. 根据取出的渠道号修改AndroidManifest.xml文件并打包
1. 存储渠道号
我选择存在新建的build.properties中,这样可以和打包的分离,当然也可以放到ant.properties, project.properties, local.properties 等文件中。
2. 取出渠道号
从properties中读取信息,xml代码如下
<property file="build.properties"/> <!-- 支持循环执行 --> <taskdef resource="net/sf/antcontrib/antcontrib.properties" > <classpath> <!-- <pathelement location="lib/ant-contrib-1.0b3.jar" /> --> <pathelement location="./ant-contrib-1.0b3.jar" /> </classpath> </taskdef> <echo>Run ant-contrib OK</echo> <target name="deploy"> <foreach target="edit_and_build" list="${market_channels}" param="channel" delimiter=","> </foreach> </target> <target name="edit_and_build"> <echo>Run '${channel}' apk</echo> <!-- flags="g" 指定全局替换,替换所有符合规则的字段 byline="false" 确认被替换的时候是一次替换一行还是多行 pattern 属性用来指明正则表达式 --> <replaceregexp flags="g" byline="false"> <regexp pattern="android:value="(.*)" android:name="CHANNEL""/> <!-- substitution expression 中是替换的值,替换的值都定义在相对应的配置文件中 --> <substitution expression="android:value="${channel}" android:name="CHANNEL"" /> <!-- fileset 属性中的 dir 用来指定被替换文件所在的目录 includes 用来指定要替换哪个文件。 --> <fileset dir="" includes="AndroidManifest.xml" /> </replaceregexp> <!-- <property name="out.release.file" location="./${channel}.apk" /> <antcall target="release" /> --> <!-- <property name="out.final.file" location="D:\ProjectDemo\${channel}.apk" /> --> <property name="out.final.file" location="D:\ProjectDemo\${channel}.apk" /> <antcall target="clean" /> <antcall target="release" /> </target> 例子下载地址:http://download.csdn.net/detail/love_world_/6257753
出处:http://blog.csdn.net/androiddevelop/article/details/11619635