关于 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 ...
随机推荐
- 关于C#的内存释放问题
最近在做一个要循环读取xml文件的功能. 想法是读取一个文件,释放一个文件,这样就不会消耗太多内存. 结果运行起来内存不停涨,最后内存溢出.用gc,disponse,异步都没有用. 后来改成relea ...
- IOS中的Block与C++11中的lambda
ios中的block 可以说是一种函数指针,但更确切的讲,其实际上其应该算是object-c对C++11中lambda的支持或者说是一个语言上的变体,其实际内容是一样的,C++的lambda我已经有简 ...
- 学习asp.net比较完整的流程[转]
如果你已经有较多的面向对象开发经验,跳过以下这两步: 第一步 掌握一门.NET面向对象语言,C#或VB.NET 我强烈反对在没系统学过一门面向对象(OO)语言的前提下去学ASP.NET. ASP.NE ...
- 使用Mulesoft建立webservice, jax-ws方式, wsdl first
先创建wsdl,然后生成class 1. 下载 HRData.xsd 和 HRDataService.wsdl http://yunpan.cn/Q4zBXC4fvC74xhttp://yunpan. ...
- HBase 实战(2)--时间序列检索和面检索的应用场景实战
前言: 作为Hadoop生态系统中重要的一员, HBase作为分布式列式存储, 在线实时处理的特性, 备受瞩目, 将来能在很多应用场景, 取代传统关系型数据库的江湖地位. 本篇主要讲述面向时间序列/面 ...
- C# 水印透明度图片
/// <summary> /// 在一张图片的指定位置处加入一张具有水印效果的图片 /// </summary> /// <param name="Sourc ...
- jQuery实用工具函数
1. 什么是工具函数 在jQuery中,工具函数是指直接依附于jQuery对象.针对jquery对象本身定义的说法,即全局性的函数,我们统称为工具函数,或Utilities函数.它们有一个明显的特征, ...
- ios开发之网络php
接着前面的学习,几天上午学习了数据库网络值php用户的注册与登录,感觉代码与ios上的oc太相似了,因此学习下来没什么障碍了,下面是代码: 首先是javascript.html文件中: <!DO ...
- vs2013发布网站
第一次在Server2008中发布网站,期间发生了很多的错误,这里记录下来,以供以后的学习. (1).首先在IIS上先建一个网站,(网站名称.物理路径.类型 IP地址 和端口)然后点击确认,这样就是先 ...
- lightoj1348
//Accepted 6004 KB 924 ms /* source: lightoj1348 time :2015.5.29 by :songt */ /*题解: 树链剖分 */ #include ...