必要的java、android、ant文件及循环打包用到的ant的jar

下载Ant(这里的Ant不是eclipse和android SDk里面自带的ant)
     官方下载地址:http://ant.apache.org/
循环打包用jar  ant-contrib-1.0b3.jar  翻墙进   http://ant-contrib.sourceforge.net/   1.03b里的ant-contrib-1.0b3-bin.zip   放到ant的lib目录下
至于java、android的不解释,干这活告诉我没环境?
 

配置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=&quot;BaiduMobAd_CHANNEL&quot; android:value=&quot;(.*)&quot;" />
<substitution expression="android:name=&quot;BaiduMobAd_CHANNEL&quot; android:value=&quot;${channel}&quot;" />
<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 不同渠道自动打包的笔记的更多相关文章

  1. [转]使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本)

    在android4.0以后的sdk里那个脚本就失效了,主要是因为 apkbuilder这个程序不见了: 人家sdk升级,我们的脚本也要跟上趟,修改一下喽. 上网一查,大家的文章还停留在我去年的脚本程度 ...

  2. ANT自动打包U3D安卓项目研究笔记

    概述 因项目使用Atlassian Stash作为项目源码管理端,且其支持Ant命令自动编译,可使其根据最新的代码自动打包,故产生该研究Ant打包的任务.在此将研究过程及一些相关知识整理记录在此. 本 ...

  3. Android ant自动打包脚本:自动替换友盟渠道、版本号、包名

    本文最后修改时间:2014-3-10 Android项目开发时,给公司人员安装,频繁升级,版本号总需要改,太麻烦,跟着时间变,自动升级才方便. Android项目开发新版时,手机上可能要装两个版本,一 ...

  4. Ant自动打包

    在ant的官网http://ant.apache.org进行下载后apache-ant-1.8.2包 解压(存放的路径不要有中文字符) 把ant里的lib设置到环境变量:E:\Android\apac ...

  5. android自动打包方法(ant+proguard+签名)

    前段时间做了一个android的网游项目,现在优化减少体积和防止别人反编译,需要把编译后.class进行混淆,开始在网上看了一些关于 ProGuard的介绍,基本上都是使用ADT自带的打包方式,那个打 ...

  6. JAVA笔记20-容器之四Map接口、自动打包、泛型(重要)

    一.Map接口 Map提供的是key到value的映射.key不能重复,每个key只能映射一个value. 注:重复是指equals,但用equals()方法效率低,所以此处用hashCode()方法 ...

  7. Unity自动打包Apk

    unity打包apk相对来说比较容易,相信出过的人都明白,出包过程,没有大的难度,一步一操作,一步一等待,繁琐耗时,不懂的人又代替不了.这时候需求就来了,如何简单的一键打包搞定,这个就稍微有点难度,当 ...

  8. C#实现APK自动打包

    C#实现APK自动打包     最近做了一个安卓项目,其中有一个自动打包的功能,要把供应商id写入APK后打包.   一.思路     在AndroidMinifest.xml中加入一个标识字段,如下 ...

  9. Android Studio Gradle 多渠道自动打包,动态修改HostUrl,签名apk,混淆配置详解

    文/ skay csdn博客:http://blog.csdn.net/sk719887916/article/details/40541163 最近遇到项目从Eclispe迁移到Android st ...

随机推荐

  1. API查看Web App发布版本+编译时间+环境变量

    项目环境: JDK7+Maven3.04 项目架构:SpringMVC 方法一:API访问Maven生成的MANIFEST.MF 1. 在pom.xml中添加jar包支持 <dependency ...

  2. js中,全局变量与直接添加在window属性的区别

    在js中定义的全局变量是挂在window下的,而window的属性也一样,那么这两者有什么区别呢? 其实这两者还是有小小的区别的,全局变量是不能通过delete操作符删除的,而直接定义在window上 ...

  3. 用wget下载整个目录

    wget -c -r -np -P files www.test.com/dir/src -c 断点续传 -r 递归下载 -np 不下载父附录 -nd 不建立目录,若无此选项,将按照网站目录结构创建目 ...

  4. linux环境下安装tomcat并配置tomcat日志分割

    1.直接解压apache-tomcat-7.0.69.tar.gz 存放在/home目录下 根据需要自定义tomcat名称 mv apache-tomcat-7.0.69 Tomcat7 2.解压cr ...

  5. 杭电ACM1003

    原题: Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. VMware下利用ubuntu13.04建立嵌入式开发环境之二

    之前在VMware中安装完Ubuntu系统,接下来开始设置开发中用到的服务和工具,以及系统设计. 1.安装VMware工具:打开VMware软件,在菜单->VM->Install VMwa ...

  7. 'java'不是内部或外部命令,另一个解决办法

    我知道环境变量,也知道搞系统变量.别给我粘那些教程了,我的java路程是C:\Program Files\Java\jdk1.6.0_05谁弄好了把那三个变量和值发出来.... JAVA_HOME=C ...

  8. DOM位置参数

    以chrome浏览器测试为准 scrollwidth scrollheight clientwidth clientheight offsetwidth offsetheight 对象的实际宽高 包括 ...

  9. 自顶而下设计FPGA

    对IC设计而言,FPGA设计层级大致包括:系统级和行为级,RTL级,门级和晶体管级.然而更普遍的情况,FPGA只是用作实时数据采集控制.某些快速处理算法.PCIe\DDR3等高速数据通道,甚至某些简单 ...

  10. CSS3的透明度使用

    大家在敲代码的时候总会遇见一个问题.就是透明度opacity 会导致整个元素内全部都会改变,通常的方法是在同级元素后面再加上一个元素标签,但是现在有CSS3 ,我们完全不用这么做了.看代码 <! ...