关于 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 ...
随机推荐
- Asp.net MVC与Javascript
特性验证 首先:在web.config文件中<appSettings>节点内添加<add key="ClientValidationEnabled" value= ...
- CFD计算
47 求解器为flunet5/6在设置边界条件时,specify boundary types下的types中有三项关于interior,interface,internal设置,在什么情况下设置相应 ...
- ubuntu 13.04 telnet 详细配置
1. sudo vi /etc/xinetd.d/telnet并加入以下内容:# default: on# description: The telnet server serves telnet s ...
- wp8开发笔记之应用程序真机发布调试
写在前面的话: 相信很多和我一样关注wp8动态以及已经开发了一些wp8应用程序的朋友们都遇到过这样的问题,写的程序在模拟器上进行调试总是显的没什么说服力,想拿真机进行实际测试, 该怎么办才好呢? 进行 ...
- 支付宝即时到账API,网站收到回调页面,输出验证失败,log中responseTxt=错误的问题
看了网上无外乎这三种原因导致: 1.参数编码问题 2.参数多余问题 3.网络延时问题 以上三种可以参考这个网站给出的解决办法:http://blog.csdn.net/zj53hao/article/ ...
- box-shadow
box-shadow:a b c d e; a-水平位置,相对于盒子本身在水平方向的正偏移距离: b-垂直位置: c-模糊距离: d-阴影尺寸,从盒子的边框开始算起的阴影的宽度: e-阴影颜色: f- ...
- Meta http-equiv属性与HTTP头的Expires中(Cache-control)详解
一.概述 A.http-equiv顾名思义,相当于http的文件头作用,它可以向浏览器传回一些有用的信息,以帮助正确和精确地显示网页内容,与之对应的属性值为content,content中的内容其实就 ...
- Android深度探索--HAL与驱动开发----第十章读书笔记
printk函数的用法于-printf 函数类似,只不过printk函数运行在内核空间, printf函数运行在用户空间.也就是说,像Linux 驱动这样的Linux内核程序只能使用printk 函数 ...
- windows下无法创建django工程的问题
环境:python2.7 django1.7 安装好django后,将C:\Python27\Lib\site-packages\Django-1.7.7-py2.7.egg\django\bin; ...
- html学习心得
注释:浏览器会自动地在段落的前后添加空行.(<p> 是块级元素) 提示:使用空的段落标记 <p></p> 去插入一个空行是个坏习惯.用 <br /> 标 ...