最近大概用了两天的时间来研究下之前一直好奇的自动批量打包功能

就是利用ant脚本来更改AndroidManifest中的meta渠道值,打包不同的市场渠道号对应下的apk。

之前一直使用的是Eclipse自带的打包方法:

Project 右键--> Android Tools --> Export Signing Application Package或者 Project 右键-->Export --> Android --> Export Android Application

都能打开Export Android Application对话框,之后就是选择或者创建keystore,输入密码,选择保存位置,完成。

这种传统做法打一个包还好,如果要统计对比分析不同市场的下载量,那么就要在Androidmanifest中为不同的市场分配不同的的渠道号,然后发布到不同的市场(这里笔者采用的是友盟统计工具,然后可以在友盟管理后台中查看不同市场的统计分析报表),如果市场比较多的话,一个一个打包既费时又费力,所以批量打包就显得尤为重要

Ant批量打包具体步骤:


1,到   官网   上下载Ant绿色版zip archive: apache-ant-1.9.4-bin.zip [PGP] [SHA1] [SHA512] [MD5]约8M,配置系统环境变量,ANT_HOME、Path,如果在命令行输入ant home出现build failed就表现配置成功了

2,为了实现批量打包,需要使用扩展包--->ant-contrib-1.0b3.jar,到   官网   上下载,然后把jar包放到上一步apache-ant-1.9.4\lib目录下

3,进入命令行,输入 android update project -p 工程project的绝对路径,之后会在project下生成两个文件,build.xml以及local.properties

4,手动创建两个文件,ant.properties 用来配置keystore的相关信息和 custom_rules.xml用来配置批量打包的有关信息

以下是相关示例代码:

local.properties

sdk.dir=E:\\Android\\Eclipse\\android-sdk-windows
apk.dir=E:\\Android\\Ant
market_channels =Gfan,Mumayi,Baidu

ant.properties,建议把keystore文件放在工程目录下

key.store=xxx.keysotre
key.store.password=000000
key.alias=xxxx
key.alias.password=000000

custom_rules.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules" ><taskdef resource="net/sf/antcontrib/antcontrib.properties" ><classpath><pathelement location="E:/Android/Eclipse/apache-ant-1.9.4/lib/ant-contrib-1.0b3.jar" /></classpath></taskdef><target name="deploy" ><foreachdelimiter=","list="${market_channels}"param="channel"target="modify_manifest" ></foreach></target><target name="modify_manifest" ><replaceregexp flags="g" byline="false">  <regexp pattern="android:value="(.*)" android:name="UMENG_CHANNEL"" />  <substitution expression="android:value="${channel}" android:name="UMENG_CHANNEL"" />  <filesetdir=""includes="AndroidManifest.xml" /></replaceregexp><propertyname="out.final.file"location="${apk.dir}/Microinvitation_${channel}.apk" /><antcall target="clean" /><antcall target="release" /></target>
</project>

build.xml,是用命令行生成的

<?xml version="1.0" encoding="UTF-8"?>
<projectname="MainActivity"default="help" ><!--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" /><!--if sdk.dir was not set from one of the property file, thenget it from the ANDROID_HOME env var.This must be done before we load project.properties sincethe proguard config can use sdk.dir--><property environment="env" /><conditionproperty="sdk.dir"value="${env.ANDROID_HOME}" ><isset property="env.ANDROID_HOME" /></condition><!--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 the ANDROID_HOME environment variable."unless="sdk.dir" /><!--Import per project custom build rules if present at the root of the project.This is the place to put custom intermediary targets such as:-pre-build-pre-compile-post-compile (This is typically used for code obfuscation.Compiled code location: ${out.classes.absolute.dir}If this is not done in place, override ${out.dex.input.absolute.dir})-post-package-post-build-pre-clean--><importfile="custom_rules.xml"optional="true" /><!--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 --><import file="${sdk.dir}/tools/ant/build.xml" /></project>

windows下命令行到工程所在目录,输入ant即可

Ant批量打包工具的使用相关推荐

  1. android ant批量打包

    当我们对安卓项目需要分很多渠道打包的时候,批量打包工具无疑是个不二选择,批量打包的方式大概可以分为两种,第一是通过第三方的打包平台,比如360加固宝,这确实是个很好的工具,既提高了源代码的安全性能,又 ...

  2. 简单的android ant 批量打包

    友盟android统计是这样搞的,添加友盟sdk后每打一个平台的包都要修改AndroidManifest.xml里<meta-data android:name="UMENG_CHAN ...

  3. Android 使用 Ant 批量打包

    1.先下载安装 Ant,下载地址:http://ant.apache.org/ 点击打开链接: 下载完成后,安装: 1)解压Ant,比如解压到D:\download\Ant 2) 我的电脑 -> ...

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

    目前国内的安卓渠道有几百家,我们要根据不同的渠道打不同渠道的apk来统计每个渠道带来的用户数,统计每个渠道用户的存活率和活跃度等等信息,但是手动对每个渠道的APK进行签名打包实在是让人感到厌烦且低效, ...

  5. android 自动批量打包,AutopackingAndroid

    项目说明: 该项目是完成android apk的批量打包工具 支持渠道号替换,资源替换,指定文件修改.修改包名,修改内部包名等等.功能强大程度完全超过友盟等市面主流批量打包工具 作者:冰剑 QQ:21 ...

  6. 使用Ant 实现批量打包Android应用

    2019独角兽企业重金招聘Python工程师标准>>> 由于公司运维需要以及应用中需要加上应用推广的统计,往往要对应二三十个渠道,按照正常方法一个一个的去生成不同渠道包的应用,不仅浪 ...

  7. 产品打包工具的制作,ant,编译源码,打jar包,打tag,打war包,备份release版本等...

    1.  在进行打包工具的制作前,需要准备的软件有: svnant-1.3.1 作用是让ant和svn相关联 apache-ant-1.9.7 需要设置ant_home,path,我的配置是: ANT_ ...

  8. 产品打包工具的制作,ant,编译源码,打jar包,打tag,打war包,备份release版本等

    1.  在进行打包工具的制作前,需要准备的软件有: svnant-1.3.1 作用是让ant和svn相关联 apache-ant-1.9.7 需要设置ant_home,path,我的配置是: ANT_ ...

  9. ant 实现批量打包android应用

    很多的应用中需要加上应用推广的统计,如果一个一个的去生成不同渠道包的应用,效率低不说,还有可能不小心弄错了分发渠道,使用ant可以批量生成应用. 一.添加渠道包信息 为了统计渠道信息,就不得不在程序的 ...

最新文章

  1. 聊一聊js中的null、undefined与NaN
  2. ubuntu系统下matplotlib中文乱码问题
  3. jira以及jira API简单介绍
  4. 下载:Visual Studio 2012 RC候选版
  5. 模型参数优化(一):遗传算法
  6. SD--订单最小量限制的增强
  7. 魔方内部长啥样?三维动画展示其结构,谁发明的真是个天才
  8. ASP.NET 2.0中将 GridView 导出到 Excel 文件中
  9. a/a的4种链接方式
  10. php访问url json,PHP操作URL和PHP操作json
  11. Spring(二)--FactoryBean、bean的后置处理器、数据库连接池、引用外部文件、使用注解配置bean等...
  12. SQL Server2005 Reporting Services的卸载
  13. 使用TensorFlow.js从网络摄像头进行实时AI情感检测
  14. android 睡眠与唤醒I
  15. [Latex排版]之visio图转成eps的方法
  16. 自定义控件的构建(6)
  17. Qt5调用VBS脚本
  18. GPU和CPU芯片区别:为何要用GPU挖矿?
  19. margin-left:-100%理解
  20. 深入浅出Java反射原理和使用场景

热门文章

  1. API调用,淘宝天猫、1688、京东、拼多多商品页面APP端原数据获取
  2. 手持PDA和手机有什么区别?
  3. 科技赋能拉萨之“肺”,华为助力拉鲁湿地智慧管理守护绿水青山
  4. 大数据投资人必读:中国大数据发展与投资分析报告
  5. 《⑨也懂系列:GNU Emacs安装教程Ver.2》世界著名的顶级全能文本编辑器
  6. Web前端是什么?主要是干什么的
  7. html语言加图片,html代码——给图片加边框代码
  8. [注塑]各种进胶方式优缺点分析
  9. DOTA英雄 精美图片 大集合
  10. mysql数据库表格数据类型_MYSQL数据库数据表字段类型含义解释