之Apache Ant 初學入門一

背景:

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_HOME
	variable 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 recom	mended 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 user	convinience. With that set you can just start ant instead of always typing the/complete/path/to/your/ant/installation/bin/ant. 強烈推薦安裝JDK。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章