关于 ant 不同渠道自动打包的笔记
必要的java、android、ant文件及循环打包用到的ant的jar
配置android、java、ant的path
如果ant要求的java版本不符
可修改注册表(当时没修改,一般没问题)将java的path放在system32之前,并将java中的java、javax、javaw三个文件复制替换system32中对应的三个文件,再次运行ant -version则ant正常
使用ant编译必须让所有编译中的项目(包括作为lib的项目)中存在ant环境文件(build.xml等)使用android update project(lib-project) -p 文件绝对路径 -t SDK版本号(版本号可使用android list target命令查看API等级在本地对应的版本号)进行初始化
使用ant编译需要项目中有ant.properties文件作为ant编译时的配置文件,其中主要规定了build.xml中需要用到的一些配置如输出路径、Keystore信息、渠道代号等。
通过直接新建文本文档,更改文件名称及后缀名来创建ant.properties文件即可,之后在文件中写入各种信息。
--------------------------------------------------------------------ant.properties start---------------------------------------------------------------
# the config file for batch package.
application.package=com.weixueji.app 包名
ant.project.name=tol-android 项目名
java.encoding=utf-8 编码格式
out.absolute.dir=C:/compile 输出文件的绝对路径(中转)
gos.path=e:/Users/weishiji/Desktop/apks 最终打包文件的绝对路径
key.store=D:/tol-android/keystore/weixueji.keystore 证书位置
key.store.password=123456 证书密码
key.alias=wxj 用到的证书别称(eclipse里就是第二次选的那个)
key.alias.password=123456 别称密码
app_version=2.1 版本号
market_channels=1,2 渠道名(必须在同一行,用英文逗号分隔)
--------------------------------------------------------------------ant.properties end---------------------------------------------------------------
以下build代码 注意替换黑字部分 其中 BaiduMobAd_CHANNEL 是渠道代码,因为我的项目中有百度统计,所以这里不一样,这里有些特殊说明后面马上讲到。
<?xml version="1.0" encoding="UTF-8"?>
<project name="项目名称" 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 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"/>
<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 -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="D:/apache-ant-1.9.4-bin/apache-ant-1.9.4/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<property name="aapt.ignore.assets" value="!.svn:!.git:\x3Cdir\x3E_*:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:crunch" />
<import file="${sdk.dir}/tools/ant/build.xml" /> <target name="deploy">
<foreach target="modify_manifest" list="${market_channels}" param="channel" delimiter=",">
</foreach>
</target> <target name="modify_manifest">
<replaceregexp flags="g" byline="false">
<regexp pattern="android:name="BaiduMobAd_CHANNEL" android:value="(.*)"" />
<substitution expression="android:name="BaiduMobAd_CHANNEL" android:value="${channel}"" />
<fileset dir="" includes="AndroidManifest.xml" />
</replaceregexp>
<antcall target="clean" />
<antcall target="release"/>
<copy tofile="${gos.path}/打包后的名称前缀${channel}.apk">
<fileset dir="${out.absolute.dir}/" includes="打包后的名称前缀-release.apk" />
</copy>
<delete includeEmptyDirs="true">
<fileset dir="${out.absolute.dir}" includes="**/*"/>
</delete>
<echo message="==========================="/>
</target>
</project>
以上为项目的build.xml文件
刚刚说过渠道id
下面讲下到底要换成什么
项目中有<meta-data android:name="BaiduMobAd_CHANNEL" android:value="yingyonghui" />来区别不同的渠道
注意由于ant循环打包的时候会用正则去匹配并替换这段值所以一定要保证AndroidManifest里这段代码为同一行 并且BaiduMobAd_CHANNEL处与build中的BaiduMobAd_CHANNEL对应
当然如果你能自己理解并写好这段替换代码可以自己去写,我是个渣渣还是用查好的吧。
下面就可以再cmd中进入到项目根目录 执行编译 ant deploy
报错什么 几 字节 utf-8 未识别啥的 可能是由于ant在循环打包时会读写AndroidManifest文件,所以如果其中有中文(包括注释)便会出问题,去掉中文注释即可。
报错引用的项目build可能是没有update的原因,使用android 的update命令去让他自动生成对应的build文件后再次执行编译
<property name="aapt.ignore.assets" value="!.svn:!.git:\x3Cdir\x3E_*:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:crunch" />
当初没有加这行代码就报错sdk中的ant build 第六百一十几行?有问题,在项目的build文件中加入即可。原理不造~有造的请指教。
暂时就能记住这么多了。
关于 ant 不同渠道自动打包的笔记的更多相关文章
- [转]使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本)
在android4.0以后的sdk里那个脚本就失效了,主要是因为 apkbuilder这个程序不见了: 人家sdk升级,我们的脚本也要跟上趟,修改一下喽. 上网一查,大家的文章还停留在我去年的脚本程度 ...
- ANT自动打包U3D安卓项目研究笔记
概述 因项目使用Atlassian Stash作为项目源码管理端,且其支持Ant命令自动编译,可使其根据最新的代码自动打包,故产生该研究Ant打包的任务.在此将研究过程及一些相关知识整理记录在此. 本 ...
- Android ant自动打包脚本:自动替换友盟渠道、版本号、包名
本文最后修改时间:2014-3-10 Android项目开发时,给公司人员安装,频繁升级,版本号总需要改,太麻烦,跟着时间变,自动升级才方便. Android项目开发新版时,手机上可能要装两个版本,一 ...
- Ant自动打包
在ant的官网http://ant.apache.org进行下载后apache-ant-1.8.2包 解压(存放的路径不要有中文字符) 把ant里的lib设置到环境变量:E:\Android\apac ...
- android自动打包方法(ant+proguard+签名)
前段时间做了一个android的网游项目,现在优化减少体积和防止别人反编译,需要把编译后.class进行混淆,开始在网上看了一些关于 ProGuard的介绍,基本上都是使用ADT自带的打包方式,那个打 ...
- JAVA笔记20-容器之四Map接口、自动打包、泛型(重要)
一.Map接口 Map提供的是key到value的映射.key不能重复,每个key只能映射一个value. 注:重复是指equals,但用equals()方法效率低,所以此处用hashCode()方法 ...
- Unity自动打包Apk
unity打包apk相对来说比较容易,相信出过的人都明白,出包过程,没有大的难度,一步一操作,一步一等待,繁琐耗时,不懂的人又代替不了.这时候需求就来了,如何简单的一键打包搞定,这个就稍微有点难度,当 ...
- C#实现APK自动打包
C#实现APK自动打包 最近做了一个安卓项目,其中有一个自动打包的功能,要把供应商id写入APK后打包. 一.思路 在AndroidMinifest.xml中加入一个标识字段,如下 ...
- Android Studio Gradle 多渠道自动打包,动态修改HostUrl,签名apk,混淆配置详解
文/ skay csdn博客:http://blog.csdn.net/sk719887916/article/details/40541163 最近遇到项目从Eclispe迁移到Android st ...
随机推荐
- python学习04——列表的操作
笨办法学python第38节 如何创建列表在第32节,形式如下: 本节主要是讲对列表的操作,首先讲了 mystuff.append('hello') 的工作原理,我的理解是,首先Python找到mys ...
- MRPT笔记——使用编译好的MRPT库建立VS2013项目
接着上一篇<MRPT在VS2013中的配置>,下面接收如何使用编译好的MRPT建立工程项目. 一.设置环境变量 上一篇中,配置MRPT时,使用到了几个相关库,opencv.zlib.wxW ...
- OC基础--对象做参数在方法间传递
剧情描述: 美国大兵抗把汉阳造 拿着5个弹夹(每个弹夹5发子弹) 带着弟兄们干架 子弹打完了就求救 类: 士兵: 属性: 姓名(_name) 身高(_height) 体重(_weight) 行为: 开 ...
- 常见JDBC连接数据库字符串
1.Mysql 驱动类:com.mysql.jdbc.Driver 连接字符串:jdbc:mysql://localhost:3306/dbname 2.Oracle 驱动类:oracle.jdbc. ...
- linux基本常用命令列举
上回装完虚拟机中的linux系统了,进入找到terminal,打开命令行界面 pwd:展示目前为止绝对路径 cd cd~:跳转到/home/yy的位置 cd-:跳转到上一步的位置 cd path(绝对 ...
- php 目录函数和日期函数
continue . break . exit目录函数opendir(); 打开一个文件夹is_file 只判断文件是否存在: file_exists 判断文件是否存在或者是目录是否存在: is_di ...
- 字符串判断设置TextView高度
问题:项目中需要根据字符串的长度判断Textview的高度 一.如果全是英文的也比较容易,根据长度判断从而设置mTextView的高度就好. double temp = str.length(); ...
- OpenSSL 使用拾遗(一)---- 生成 pkcs12 文件
从本期开始,记录一些在使用 OpenSSL 过程中碰到的问题及解决办法 在 Linux 下需要生成 pkcs12 文件,立即想到 OpenSSL.键入如下命令 ~ # openssl pkcs12 - ...
- 北大poj- 1045
Bode Plot Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14060 Accepted: 8820 Descri ...
- 一些初级Java错误,不定期增加
1. Error: Dangling meta character '*' near index 0 对字符串使用split()方法截取 * ? + / | 等字符的时候会报以下异常 Dangling ...