<程序猿--艰难历程>之Apache Ant 初学入门一

来源:互联网 发布:科技部 自评估软件 编辑:程序博客网 时间:2024/04/30 21:09

背景:

Android开发工作也做了一段时间了,但是发现平时项目的纳品打包,总是要手动来完成、还要反反复复地进行版本、文件的核对工作,程序麻烦,还容易造成疏忽……通过调查,发现Android其实可以使用Ant进行快速的编译、打包、签名等系列工作。。。所以近几天开始研究API Doc,现在记录下研究心得~


内容:

Android Develop Tools doc -- Building and Running from the Command Line 使用Ant工具方式完成编译打包签名发布工作。

Android的Building有两种方式:In debug mode & In release mode。

In debug mode:只需要使用Debug keystore即可,编译出以签名、并zipalign的apk。

In release mode:首先会编译一份unsigned的apk,然后进行sign签名、zipalign work,才能得到可以使用的apk。

PS:发布apk,必须是release version的。


下面说下Ant的下载、安装和使用:

下载(Download):

   首先进入Apache Ant home page:http://ant.apache.org/index.html. Here,有两个版本的ant可供下载使用source&bin区别 

   Windows下载.zip  Unix/Linux下载.tar.gz

      目前最新版本May 23, 2012 - Apache Ant 1.8.4 Released :下载source ; 下载bin

      下载完成以后,首先需要Check  [PGP] [SHA1] [SHA512] [MD5]此处本人验证的是[MD5].

PS:关于PGP验证,是最Recommended的,但是Gpnup软件的下载貌似有点麻烦,地址是http://www.gnupg.org/download/ 

    关于Ant、PGP的下载,都涉及到一个mirror的网络地址概念,这是一个镜像地址:简单理解就是,他们本身都有一个original服务器,因为全球化,所以时机不可能每一个人都去访问这个original服务器,所以,他们一般会在各个地区主要国家再一步部署可供用户访问的间接服务器,这个间接服务器就是mirror服务器,对应的地址就是mirror site。在下载时,只需要找到nearby mirror site即可。


Ant.zip包目录结构:

The binary distribution of Ant consists of the following directory layout:

  ant   +--- README, LICENSE, fetch.xml, other text files. //basic information   +--- bin  // contains launcher scripts   |   +--- lib  // contains Ant jars plus necessary dependencies   |   +--- docs // contains documentation   |      |   |      +--- images  // various logos for html documentation   |      |   |      +--- manual  // Ant documentation (a must read ;-)   |   +--- etc // contains xsl goodies to:            //   - create an enhanced report from xml output of various tasks.            //   - migrate your build files and get rid of 'deprecated' warning            //   - ... and more ;-)
如果Run Ant,only bin\ & lib\ required.


安装(Install):  PS ant是一个tool,所以一般下载Bin Edition apache-ant-1.8.4-bin.zip;下载完成以后

1、验证[MD5],Win7开始,搜索框输入MD5,会有一个MD5校验器;

2、解压apache-ant-1.8.4-bin.zip至intall_dir;(注意目录下的内容)我的解压路径intall_dir = G:\apache-ant-1.8.4-bin\apache-ant-1.8.4 

3、设置JDK环境变量JAVA_HOME、Ant环境变量ANT_HOME;CALSSPATH不用设置,如果设置了,可能出问题。

电脑属性-高级-环境变量:用户变量——New,variable name=ANT_HOMEvariable value=G:\apache-ant-1.8.4-bin\apache-ant-1.8.4系统变量 path打开,追加;G:\apache-ant-1.8.4-bin\apache-ant-1.8.4\bin 或者%ANT_HOME%\bin,但是我的电脑使用%%\bin确实不通过;不知道为什么?

Check Installation:

运行cmd,输入ant. 输出:Buildfile: build.xml does not exist!              Build failed表示安装成功;否则,提示ant不是‘内部’或‘外部’命令。  如果失败,则首先要检查自己的环境变量是否设置正确。

说明下变量的意义:

ANT_HOME is used by the launcher script for finding the libraries. JAVA_HOME is used by the launcher for finding the JDK/JRE to use. (JDK is recommended as some tasks require the java tools.) If not set, the launcher tries to find one via the %PATH% environment variable. PATH is set for userconvinience. With that set you can just start ant instead of always typing the/complete/path/to/your/ant/installation/bin/ant. 强烈推荐安装JDK。