Android中利用ant进行多渠道循环批量打包(一)

来源:互联网 发布:js map foreach 编辑:程序博客网 时间:2024/05/22 10:30

目前国内的安卓渠道有几百家,我们要根据不同的渠道打不同渠道的apk来统计每个渠道带来的用户数,统计每个渠道用户的存活率和活跃度等等信息,但是手动对每个渠道的APK进行签名打包实在是让人感到厌烦且低效,这时我们需要一个全自动化的打包工具----ant。Android SDK的tools中已经包括了ant的打包工具,那么我们该如何运用它达到我们的要求呢?之前卤煮做这块的时候也参考了很多前辈的文章,首先向前辈们致敬,下面说下卤煮的方法,有什么不对的地方或者疑问欢迎大家留言交流。(以下步骤均在MAC系统下完成)

一.打包前准备工作

1.首先确定你的JDK版本为1.6!

2.在AndroidManifest.xml中application标签下添加一个用来识别渠道的标签:

<meta-data  android:name="qudao"  android:value="channel" />

3.为了让ant支持循环功能,我们要在Android SDK/tools/lib下放一个ant-contrib-1.0b3.jar包

4.项目中放置第三方jar包的文件夹必须叫libs而不是lib

 

二.build.xml等文件的生成和配置

1.通过终端(cmd)命令自动生成build.xml和local.properties两个文件,方法如下:

<sdk>/tools/android update project -p <project> -t <target>

例如:

/Users/moushou/Downloads/AndroidSDK/tools/android update project -p /Users/moushou/Documents/workspace/HelloWorld -t 14

其中<sdk>为SDK全路径,<project>为项目全路径,<target>为API版本。

执行完成截图如下:

执行完成后,Refresh你的项目就会发现项目的根目录下多了两个文件:build.xml和local.properties

其中local.properties的内容是:

# This file is automatically generated by Android Tools.# Do not modify this file -- YOUR CHANGES WILL BE ERASED!## This file must *NOT* be checked into Version Control Systems,# as it contains information specific to your local configuration.# location of the SDK. This is only used by Ant# For customization when using a Version Control System, please read the# header note.sdk.dir=/Users/moushou/Downloads/AndroidSDK

project.properties的内容如下:

# This file is automatically generated by Android Tools.# Do not modify this file -- YOUR CHANGES WILL BE ERASED!## This file must be checked in Version Control Systems.## To customize properties used by the Ant build system use,# "ant.properties", and override values to adapt the script to your# project structure.#proguard.config=proguard.cfg# Project target.target=Google Inc.:Google APIs:14proguard.config=proguard.cfg

项目的目录结构如下图所示:

:project.properties中target=GoogleInc.:GoogleAPIs:14代表所使用的SDK的版本,可进行手动修改。

2.手动为项目新建一个File,该文件名为:ant.properties,创建完成项目的目录结构如下图:

创建完成后在ant.properties中添加如下内容:

key.store=<keystore>key.alias=<key>key.store.password=<keystore pwd>key.alias.password=<key pwd>market_channels=xx,yy,zzapp_version=1_0_build_0

例如:

key.store=/Users/moushou/Desktop/qianmingkey.alias=meilihuaduokey.store.password=123456xxkey.alias.password=123456xx market_channels=anzhuoshichang,jifengshichang,baiduyingyongzhongxinapp_version=1_0_build_0

其中:

keystore为签名文件的全路径。

key.alias为签名需要使用的私钥。

key.store.password为私钥库的密码。

key.alias.password为私钥的密码。

market_channels为渠道集合。

app_version为apk的版本(此字段可根据自己喜好编写)。

 

--------------------------------------------------------------------------------------------------

 

至此,除build.xml外,其余文件配置完成,夜深人静的让我有些犯困啦,明天会把build.xml中使用for循环替换AndroidManifest.xml中渠道value的方法分享给大家。

 


<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击