2019独角兽企业重金招聘Python工程师标准>>>

在没用AndroidStudio的Gradle构建项目之前,多渠道打包一般都是基于ANT构建,所以在此记录一下,以供查阅!

一、文件准备

1、首先要去官网下载ANT代码。

ANT官网下载地址

2、下载ANT循环打包JAR包。

ANT循环JAR包下载地址

网盘下载地址

3、解压得到其中的ant-contrib-1.0b3.jar文件待用。

做完以上3步,ANT多渠道打包所需要的软件就准备完毕了,接下来就是环境配置了。

二、环境配置

1、先将之前下载的ANT文件解压缩到任意文件路径,如D:\Ant目录

2、配置以下环境变量

* 我的电脑->属性->高级->环境变量
* 系统变量新建ANT_HOME,变量值为D:\Ant
* 在path变量下追加以下值,%ANT_HOME%\bin;

3、打开CMD窗口,输入ant build,如果能够看到下面的两句话,说明你得ANT环境已经配置好了。

C:\Users\ZhuWenWu>ant build
Buildfile: build.xml does not exist!
Build failed

4、ANT要支持循环打包需要安装扩展包ant-contrib,将之前解压得到的ant-contrib-1.0b3.jar文件复制到你ANT目录下得lib文件夹下。如:D:\Ant\lib

做完以上4步,ANT多渠道打包环境就基本配置好了,接下来就是真正的要来处理循环打包了。

三、多渠道打包

总共需要编辑4个文件,分别为build.xml、local.properties、customrules.xml、ant.properties. 同时准备好自己的签名文件:androidkey.keystore。

1、编辑local.properties文件内容,主要是配置SDK路径及项目路径

# 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的路径地址
sdk.dir=E:\\Android\\android-studio\\sdk
#项目路径地址
project.dir=F:\\Android\\sourceCode\\Test

2、编辑ant.properties,主要是配置ANT打包的数据

#项目包名
application.package=com.ecloud.test
#项目名称
ant.project.name=test
#项目编码,这里需要注意自己工程的编码格式,需要保证编码格式一致
java.encoding=utf-8   #编译中间文件生成目录
out.absolute.dir=F:/Test/compile
#最终APK生成文件目录
gos.path=F:/Test/test-code1-20140523  #签名文件全路径
key.store=F:/Test/Test/android_key.keystore
#签名文件密码
key.store.password=111111
#别名,这里要注意如果你签名文件的别名为中文,需要和我这个一样转成16进制,不然签名的时候会报错,转码可以用【UltraEdit工具】(自行百度下载)来做。
key.alias=\u5BB9\u6613\u901B
#别名密码
key.alias.password=111111  #软件版本号
app_version=1.0.0
#需要打包的渠道名,注意‘,’分格
market_channels=Gfan,3G,360,AndMarket,AnZi

3、编辑custom_rules.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules" ><taskdef resource="net/sf/antcontrib/antcontrib.properties" ><classpath><!--注意这里要和你拷贝的那个JAR文件相同--><pathelement location="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=&quot;(.*)&quot; android:name=&quot;UMENG_CHANNEL&quot;" />  <substitution expression="android:value=&quot;{channel}&quot; android:name=&quot;UMENG_CHANNEL&quot;" />  <filesetdir=""includes="AndroidManifest.xml" /></replaceregexp><propertyname="out.final.file"location="${apk.dir}/${ant.project.name}_${channel}.apk" /><antcall target="clean" /><antcall target="debug" /></target>
</project>

4、编辑最终的build.xml文件,这个是才是循环打包的重点

<?xml version="1.0" encoding="UTF-8"?> <!-- 项目名称test,可用全局替换为当前项目名称 -->
<projectname="test"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" /><propertyname="manifest.file"value="AndroidManifest.xml" >
</property><propertyname="bin.dir"value="bin" >
</property><propertyname="absolute-out"value="${project.dir}/${bin.dir}" >
</property><propertyname="absolute-file-manifest-out"value="${absolute-out}/${manifest.file}" >
</property><propertyname="absolute-file-manifest-src"value="${project.dir}/${manifest.file}" >
</property> <!-- 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" /><failmessage="sdk.dir is missing. Make sure to generate local.properties using &apos;android update project&apos; 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" >
注意这里的JAR包路径,要修改成自己的
    <classpath><pathelement location="D:/Ant/lib/ant-contrib-1.0b3.jar" /></classpath>
</taskdef><import file="${sdk.dir}/tools/ant/build.xml" /><target name="deploy" ><foreachdelimiter=","list="${market_channels}"param="channel"target="modify_manifest" ></foreach>
</target>
这里就是修改渠道号的代码,我的渠道值设置的是SETTINGUMENGCHANNELCHANNELIDVALUES你可以替换成你自己的
    <target name="modify_manifest" > <!-- <copy file="${absolute-file-manifest-src}" tofile="${absolute-file-manifest-out}" overwrite="true"/><replace file="${absolute-file-manifest-out}" token="SETTING_UMENG_CHANNEL_CHANNELID_VALUES" value="${channel}" encoding="UTF8"/> --><replaceregexpencoding="utf-8"file="AndroidManifest.xml"match="SETTING_UMENG_CHANNEL_CHANNELID_VALUES"replace="${channel}" /> <!-- <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" /><copy tofile="${gos.path}/test_${channel}.apk" ><filesetdir="${out.absolute.dir}/"includes="test-release.apk" /></copy><delete includeEmptyDirs="true" ><filesetdir="${out.absolute.dir}"includes="**/*" /></delete>
这里要将替换之后的渠道号值改成默认的值SETTINGUMENGCHANNELCHANNELIDVALUES,不然下一个打包时将不会替换渠道号的值
    <replaceregexpencoding="utf-8"file="AndroidManifest.xml"match="${channel}"replace="SETTING_UMENG_CHANNEL_CHANNELID_VALUES" /><echo message="===========================" />
</target>
</project>

5、把以上4个文件拷贝到项目根目录下,目录结构如下

test----src--res--libs--local.properties--custom_rules.xml--ant.properties--build.xml

6、打开CMD,然后CD到项目根路径下,运行ant deploy即可。注意在运行之前要注意先clean一下项目,不然可能会报错误,切记!!!!

BUILD FAILED
F:\Test\Test\build.xml:113: The following error occurred while executing this line:
F:\Test\Test\build.xml:139: The following error occurred while executing this line:

7、如果你看到BUILD SUCCESS,那么恭喜你,多渠道打包编译成功了,去输出目录查看一下APK文件吧!

8、多渠道打包文件下载地址

文件下载地址

转载于:https://my.oschina.net/oppo4545/blog/346778

Android ANT多渠道打包相关推荐

  1. android中多渠道打包的三种方式

    转载至:一片枫叶的专栏 国内的Android开发者还是很苦逼的,由于众所周知的原因,google play无法在国内打开(翻墙的就不在考虑之内了),所以Android系的应用市场,群雄争霸.后果就是国 ...

  2. 【Android】多渠道打包与签名机制

    [Android]多渠道打包与签名机制 多渠道打包 我们在发布APP时,往往需要生成多个渠道包,以上传到不同的应用市场. 而每个渠道包中,都可以包含各自的渠道信息,当APP和后台交互或进行数据上报时, ...

  3. Android的多渠道打包

    前言 本篇包括以下内容: 多渠道打包概述 友盟的多渠道打包 美团的多渠道打包 360的多渠道打包 多渠道打包概述 什么是多渠道包 渠道包就是要在安装包中添加渠道信息,也就是channel,对应不同的渠 ...

  4. android 自定义apk名,Android Studio多渠道打包、自定义打包APK名称

    现在为了推广产品,会在多个渠道应用市场发布应用,为了统计不同渠道的数据,需要在应用中表明渠道,如果一个一个去修改打包效率会很低.AS为我们提供了简便的方法,可以多渠道打包,一次打包所有的渠道包. 1. ...

  5. android快速打包工具下载,【Android】多渠道打包,其实可以更快

    现状 多渠道打包,相信很同学都知道.在Android Studio中只要经过配置,就能打出对应市场的渠道包.打过包的同学可能都会有这样的感受:散热器疯狂地转.打包速度那叫一个慢.这时候除了无奈,还是无 ...

  6. Android Studio 多渠道打包、自动版本号及 gradlew 命令的基本使用

    Android Studio 真可谓神器,详细请点这里:打造安卓开发航空母舰 这里介绍其多渠道打包: 1 建立多渠道 这里介绍一种简单的,直接as操作: 直接上图咯,在项目结构你添加flavor就好了 ...

  7. Android之Android Studio--Gradle多渠道打包

    于国内Android市场众多渠道,为了统计每个渠道的下载及其它数据统计,就需要我们针对每个渠道单独打包,如果让你打几十个市场的包岂不烦死了,不过有了Gradle,这再也不是事了. 友盟多渠道打包 废话 ...

  8. Android Gradle 多渠道打包、动态配置AppName

    目录 一.简介 二.Gradle多渠道打包 1.普通做法 2.Gradle多渠道打包 一.简介 因为国内Android应用分发市场的现状,我们在发布APP时,一般需要生成多个渠道包,上传到不同的应用市 ...

  9. android百度多渠道打包,Android多渠道打包方案的实践与优化

    目前使用过的多渠道打包方式有两种 ,一种是通过gradle打包,还有一种是美团的多渠道打包方案具体详情见这里 1.Gradle打包 1.1.在Androidmanifest.xml中添加 androi ...

最新文章

  1. 目标检测 | 盘点目标检测中的特征融合技巧(根据YOLO v4总结)
  2. src与href的区别
  3. JAVA写同步栈_tomcat实现的同步队列和同步栈
  4. 无需人工!无需训练!构建知识图谱 BERT一下就行了!
  5. golang 关闭gc 并手动gc_Golang垃圾回收 屏障技术
  6. c# 网口相机可以通过_双网口硬盘录像机怎么设置?录像机连接GB28181公安专网步骤指导...
  7. 应届生还是研究生?与大学生的MSN谈话二
  8. 从区块链中的通证模型设计看项目的未来
  9. 基础教程——python函数
  10. Netty源码分析(四):EventLoopGroup
  11. 如何应用Matlab plot画点
  12. 庆祝新文章在《网管员世界》发表
  13. dependency 和dependencyManagement 的区别
  14. 基于偏微分方程的图像分割(二)Snake模型 Matlab实现
  15. android开发,动态图标,Android动态加载很难?带你快速实现App图标热更新
  16. 【Linux云计算架构:第三阶段-Linux高级运维架构】第26章——tcp三次握手四次挥手及在局域网中使用 awl伪装MAC地址进行多线程SYN攻击
  17. 微信小程序地区选择,单级学校选择和省,市,区选择
  18. n个节点互异的拉格朗日插值基函数之和等于一证明
  19. RMAN Encrypted Backups
  20. cpm自动SEO写文章 关键词文本生成工具3.0版本

热门文章

  1. 旋转校正原理_【干货】全站仪水准器的检校原理及方法,值得学习!
  2. ddr4服务器内存和普通内存_国产DDR4内存上架,价格动心!
  3. editplus查找文件中的字符串
  4. 英语总结系列(二十一):英语也能玩出新花样
  5. 真·干货!这套深度学习教程整理走红,从理论到实践的带你系统学习 | 资源...
  6. 苹果无人车裁员200人,收购特斯拉呼声再起
  7. 谷歌发布Edge TPU芯片,云上模型本地运行丨附尝鲜地址
  8. “明年AI会如何?”英伟达问了13位不同行业的专家
  9. android drawable资源调用使用心得
  10. Java 理论与实践: 处理 InterruptedException(转)