700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Ant自动批量打包多渠道APK

Ant自动批量打包多渠道APK

时间:2021-08-27 13:18:54

相关推荐

Ant自动批量打包多渠道APK

一、准备工作

1. 下载安装Ant /bindownload.cgi(官网下载)

下载完成后解压到指定目录并将bin目录配置到环境变量Path中

2. 下载ant-contrib-1.0b3.jar/detail/tenggangren/5958967

由于Ant自身不支持循环命令,需要下载此扩展包来支持

二、在工程根目录下创建并编写build.xml、ant.properties、project.properties

示例:

build.xml代码

<?xml version="1.0" encoding="UTF-8"?><projectname="xuanshangbang"default="deploy" ><!--The local.properties file is created and updated by the 'android' tool.It contains the path to the SDK. It should *NOT* be checked intoVersion Control Systems.--><property file="local.properties" /><!--The ant.properties file can be created by you. It is only edited by the'android' tool to add properties to it.This is the place to change some Ant specific build properties.Here are some properties you may want to change/update:source.dirThe name of the source directory. Default is 'src'.out.dirThe name of the output directory. Default is 'bin'.For other overridable properties, look at the beginning of the rulesfiles in the SDK, at tools/ant/build.xmlProperties related to the SDK location or the project target shouldbe updated using the 'android' tool with the 'update' action.This file is an integral part of the build system for yourapplication and should be checked into Version Control Systems.--><property file="ant.properties" /><!--The project.properties file is created and updated by the 'android'tool, as well as ADT.This contains project specific properties such as project target, and librarydependencies. Lower level build properties are stored in ant.properties(or in .classpath for Eclipse projects).This file is an integral part of the build system for yourapplication and should be checked into Version Control Systems.--><loadproperties srcFile="project.properties" /><!-- quick check on sdk.dir --><failmessage="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"unless="sdk.dir" /><!--extension targets. Uncomment the ones where you want to do custom workin between standard targets--><!--<target name="-pre-build"></target><target name="-pre-compile"></target><target name="-post-compile"></target>--><!--Import the actual build file.To customize existing targets, there are two options:- Customize only one target:- copy/paste the target into this file, *before* the<import> task.- customize it to your needs.- Customize the whole content of build.xml- copy/paste the content of the rules files (minus the top node)into this file, replacing the <import> task.- customize to your needs.***************************** IMPORTANT *****************************In all cases you must update the value of version-tag below to read 'custom' instead of an integer,in order to avoid having your file be overridden by tools such as "android update project"--><!-- version-tag: 1 --><taskdef resource="net/sf/antcontrib/antcontrib.properties" ><classpath><pathelement location="D:/Ant/apache-ant-1.9.4/lib/ant-contrib-1.0b3.jar" /> <!--修改此处路径 --></classpath></taskdef><import file="${sdk.dir}/tools/ant/build.xml" /> <!--导入ant的build.xml用于编译apk --><target name="deploy" ><!--循环打包命令: market_channels(为ant.properties里配置的渠道号,用逗号隔开) --><!-- param(为将上面取出来的一个个的渠道号赋值给channel参数--><!-- target(类似Makefile,执行目标modify_manifest--><foreachdelimiter=","list="${market_channels}"param="channel"target="modify_manifest" ></foreach></target><target name="modify_manifest" ><!-- <replaceregexp file="AndroidManifest.xml" encoding="utf-8" match="android:value="(.*)"" replace=""/> --><replaceregexpbyline="false"flags="g" ><!-- 正则匹配并替换 --><!-- 在代码中要用如下图片所示代码替换 --><regexp pattern="android:name="UMENG_CHANNEL" android:value="(.*)"" /> <substitution expression="android:name="UMENG_CHANNEL" android:value="${channel}"" /> <filesetdir=""includes="AndroidManifest.xml" /></replaceregexp><!-- <property name="out.release.file" value="${out.absolute.dir}/${channel}.apk"/> --><antcall target="release" /> <!-- 调用上面导入的ant里自带的build.xml里面的release目标 --><copy tofile="${gos.path}/xuanshangbang_${app_version}_${channel}.apk" ><!-- 将每一次循环生成的apk包复制到指定目录并用(包名_版本号_渠道号)方式命名 --><filesetdir="${out.absolute.dir}/"includes="xuanshangbang-release.apk" /></copy><echo message="===========================" /></target></project>

注:拷贝build.xml到工程里去的时候, 用此代码替换上述注释需要替换的代码 ant.properties代码

<pre name="code" class="plain"><pre name="code" class="plain">application.package=com.xunlei.xuanshangbang ant.project.name=xuanshangbang java.encoding=utf-8out.absolute.dir=d:/xuanshangbang_apk_channelsgos.path=d:/xuanshangbang_apk_channels/apks#配置签名的路径、密码、别名、别名密码#注:千万不要在值后面输入额外的空格字符,否则会因为密码不正确而报Build Failed!!!key.store=D:/xuanshangbang_apk_channels/XuanShangBangKeykey.store.password=xljfqxsbkey.alias=xuanshangbangkey.alias.password=xljfqxsbapp_version=1.0.0.26#配置渠道号,以逗号隔开输入,不要输入回车符等额外的字符market_channels=0x11100001,0x11100002,0x11100003,0x11100004,0x11100005,0x11100006,0x11100007,0x11100008,0x11100009,0x1110000A,0x1110000B,0x1110000C,0x1110000D,0x1110000E,0x1110000F,0x11100010,0x11100011,0x11100012,0x11100013,0x11100014,0x11100015,0x11100016,0x11100017,0x11100018,0x11100019,0x1110001A,0x1110001B,0x1110001C,0x1110001D

project.properties代码

#在原来的project.properties最后面加上一句#记得加上斜杠转义符sdk.dir=D:\\ADT_Bundle\\adt-bundle-windows-x86_64-0702\\sdk

最后, cmd进入工程根目录,执行ant deploy即可

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。