1.先下载安装 Ant,下载地址:http://ant.apache.org/ 点击打开链接;

下载完成后,安装:

1)解压Ant,比如解压到D:\download\Ant

2) 我的电脑 -> 属性-> 高级-> 环境变量

3)系统变量新建 ANT_HOME, 变量值为 D:\Android\Ant

4) 系统变量新建或修改 path, 变量值为 %ANT_HOME%\bin

操作结束后,在Dos窗口输入ant 回车,如果出现:

Buildfile: build.xml does not exist!

Build failed

表明 ant 已经安装完毕了。

2. 安装扩展包 Ant_contrib,支持循环打包。

1)到http://sourceforge.net/projects/ant-contrib/files/ant-contrib/ 点击打开链接下载1.0b3

2)从下载的压缩包复制ant-contrib-1.0b3.jar到Ant的lib文件夹中。

3.1 在工程的根目录下创建文件 build.xml.(除此之外还需要新建3个文件ant.properties、local.properties、custom_rules.xml,在build文件中会引用这三个文件,也可以将三个文件内容都放在build.xml中)

内容:

<?xml version="1.0" encoding="UTF-8"?>
<project name="应用名称" 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 into
         Version 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.dir
             The name of the source directory. Default is 'src'.
         out.dir
             The name of the output directory. Default is 'bin'.

For other overridable properties, look at the beginning of the rules
         files in the SDK, at tools/ant/build.xml

Properties related to the SDK location or the project target should
         be updated using the 'android' tool with the 'update' action.

This file is an integral part of the build system for your
         application and should be checked into Version Control Systems.

-->
    <property file="ant.properties" />

<!-- if sdk.dir was not set from one of the property file, then
         get it from the ANDROID_HOME env var.
         This must be done before we load project.properties since
         the proguard config can use sdk.dir -->
    <property environment="env" />
    <!-- LL改用自己指定的SDK
    <condition property="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 library
         dependencies. 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 your
         application and should be checked into Version Control Systems. -->
    <loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
    <fail
            message="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
    -->
    <import file="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>

3.2 ant.properties文件内容

application.package= 包名
java.encoding=utf-8

out.absolute.dir= E:/PD/Ant/compiletemp //编译临时文件存放位置
gos.path=E:/PD/Ant/apk/APP2.2 //打包的应用存放位置

key.store=E:/PersonalData/Ant/app.keystore // keystore 存放位置
key.store.password=123456 //keystore密码
key.alias=app
key.alias.password=123456

app_version=2.2 //应用版本号
market_channels=1001,1002(渠道号)

3.3 local.properties 内容

sdk.dir=D:\\soft\\adt-bundle-windows-x86-20130917\\sdk  //SKD安装位置

3.4 custom_rules.xml 内容

<?xml version="1.0" encoding="utf-8"?>
<project >
    
    
<!-- 声明ant loop ,直接用ant的循环功能,批处理什么的又要多写代码 -->
   <taskdef resource="net/sf/antcontrib/antcontrib.properties" >
        <classpath>
            <pathelement location="${sdk.dir}/tools/lib/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>

<path id="lib-classpath">  
    <fileset dir="${from.dir}/lib"><!--4-->
<include name="**/*.jar"/> 
</fileset> 
<fileset dir="${from.dir}/libs"><!--4-->
       <include name="**/*.jar"/> 
</fileset> 
<fileset dir="${from.dir}/libs/armeabi"><!--4-->
   <include name="**/*.so"/> 
</fileset> 
    </path>

<!-- 这里相当于一个方法把,(表示ant不会,只能看懂= =) ,以后可以用命令行 ant deploy 来表示批量打包 -->
<!-- ${market_channels} 要在local.properties里声明,并用,来分隔你要打包的channel名 -->
<!-- 比如我的local.properties里是这样写的   market_channels=Google,Gfan,AnZhi,MuMayi -->
    <target name="deploy" >
        <foreach
            delimiter=","
            list="${market_channels}"
            param="channel"
            target="modify_manifest" >
        </foreach>
    </target>

<!-- 修改manifest.xml里的渠道名,如果你要改其他文件,举一反三把 -->
<!-- regexp pattern是正则匹配,这里双引号要用&quot;而不是\ -->
<!-- substitution expression 是你要替换的的channel名-->
<!-- 打包完毕后要把apk移动到一个指定的目录把,你可以在sdk/tools/ant/build.xml搜下out.final.file这个property在哪用到的-->
<!-- <property name="out.final.file" location="${apk.dir}/XXX_{channel}.apk" />  ${apk.dir}表示你要指定的apk目录 XXX表示你要定义apk名和${channel}渠道号-->
<!-- <antcall target="clean" /> <antcall target="release" /> release之前要调下clean,不然以后改的channel名不生效,你懂得-->
    <target name="modify_manifest" >
       <!--  <property
         <replaceregexp flags="g" byline="false">  
    <regexp pattern="android:value=&quot;(.*)&quot; android:name=&quot;UMENG_CHANNEL&quot;" />  
    <substitution expression="android:value=&quot;${channel}&quot; android:name=&quot;UMENG_CHANNEL&quot;" />  
           <fileset
                dir=""
                includes="AndroidManifest.xml" />
        </replaceregexp>-->
       <!--  <property
            name="out.final.file"
            location="${apk.dir}/XXX_${channel}.apk" />-->
        <replaceregexp flags="g" byline="false" encoding="utf-8">  
<regexp pattern="&lt;string name=&quot;channel&quot;&gt;(.*)&lt;/string&gt;" />  
<substitution expression="&lt;string name=&quot;channel&quot;&gt;${channel}&lt;/string&gt;" />  
  <fileset dir="${resource.absolute.dir}" includes="values/strings.xml" />
        </replaceregexp>
<echo level="info"> ${channel} haahhhahahahahahahahahhahahahahahaahhahahhah</echo>
<!--<replace file="res/values/strings.xml" token="_channel_" value="${channel}" />-->
        <antcall target="clean" />
        <antcall target="release" />

<!--<copy todir="${to.dir}\TestAnt_release_${channel}" >
<fileset dir="${from.dir}" >
  <include name="TestAnt-release.apk" />
</fileset>  
        </copy>--> 
   <copy 
       file="${out.absolute.dir}\应用名称.apk" 
       tofile="${gos.path}\LJHSuperMarket_${app_version}_${channel}.apk" />
    </target>
</project>

4. 完成以上几个步骤以后在 ADE中右键build.xml然后Run as -> ant build以后就可以打包了。

Android 使用 Ant 批量打包相关推荐

  1. 简单的android ant 批量打包

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

  2. Ant批量打包工具的使用

    最近大概用了两天的时间来研究下之前一直好奇的自动批量打包功能 就是利用ant脚本来更改AndroidManifest中的meta渠道值,打包不同的市场渠道号对应下的apk. 之前一直使用的是Eclip ...

  3. android ant批量打包

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

  4. android打包工具多渠道批量打包,Android 快速渠道批量打包详解教程-美团多渠道打包方案...

    今天写一篇文章来总结下android批量打渠道包美团版本.之前项目上一直用的是gradle 批量打包方式,那个速度啊真是令人发指,15个渠道得跑上半个小时,出去吃顿饭回来,还在跑.特别是赶上项目上线的 ...

  5. android 美团批量打包,Android 快速渠道批量打包详解教程-美团多渠道打包方案

    今天写一篇文章来总结下android批量打渠道包美团版本.之前项目上一直用的是gradle 批量打包方式,那个速度啊真是令人发指,15个渠道得跑上半个小时,出去吃顿饭回来,还在跑.特别是赶上项目上线的 ...

  6. android 自动批量打包,AutopackingAndroid

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

  7. linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件...

    原创,转载请注明:http://www.cnblogs.com/ycxyyzw/p/4555328.html  之前写过一篇<windows下Android利用ant自动编译.修改配置文件.批量 ...

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

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

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

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

最新文章

  1. 如何获得PMP认证证书
  2. 决策树ID3、决策树C4.5、决策树CART、CART树的生成、树的剪枝、从ID3到CART、从决策树生成规则、决策树优缺点
  3. python 时间格式 工作日_python使用time、datetime返回工作日列表实例代码
  4. SQL -- 是否或推断线相交以在其内部的平面
  5. python linux 优化_Linux性能优化(一)
  6. lineNumber: 1; columnNumber: 1; 前言中不允许有内容
  7. python怎么导入数据集keras_python – 如何为Keras准备数据集?
  8. SpringBoot修改默认端口号
  9. 图像形状特征(七)--Zernike矩
  10. (转)曹锋、宋天玮:区块链技术在证券市场中的应用探索
  11. matlab微积分如何计算器,利用matlab进行微积分的计算.pptx
  12. 旋转矩阵和角速度之间的关系
  13. linux 云计算 python web和http协议
  14. H5页面调用微信支付
  15. 【软件测试】测试员vs测试工程师,你是测试员还是测试工程师?
  16. id门禁卡复制到手机_门禁卡复制到手机苹果
  17. wireshark抓rtsp rtp rtcp包手把手教你分析包结构 H264 H265
  18. JEECG Excel 工具类
  19. 最大流算法之一——EK算法
  20. ]一周热文推荐:致应届毕业生——程序员的生存法则

热门文章

  1. MSN, 迅雷等调用小红伞作为杀毒软件的方法
  2. GNU链接脚本(06) - SECTIONS指令
  3. Kali之——设置静态IP
  4. IT大四考研还是就业?2022考研内卷有多严重
  5. AltiumDesigner PCB设计规则中英文对照及说明
  6. 自己申请计算机软件著作权可以下载电子版原件了?
  7. asciinema终端录屏神器使用及过坑
  8. Jenkins升级大坑-插件问题
  9. Latex 图片/表格位置不正确
  10. 第8天:鼠标控制与32位模式切换