角色上就跟用來 build c project 的 Make 一樣。
那為什麼要特別做一個 tool 呢?
有什麼是 Make 做不到的 ?
這一篇有說明:
大概是因為啟動 javac 的時間很長,所以compile java 傾向於一次 compile 很多 java file.
和 c 一次compile 一個差異很大。
加上 target-depends rules 的更動,不太容易處理階層性的 source code.
所以才重寫了 make 的 tool
所以,就把 ant 當 make 就好了
make 是吃 Makefile
ant 是吃 build.xml (default)
是 xml 格式。
大約也跟 makefile 一樣,定義變數,定義 target, 然後有 action
同意也有 include 的功能。
還有一些定義另外分別開來,叫 property file, 或 config 檔,。
啟動ant 的 command 大概就是:
ant -v -f build.xml加上 -v 是output message,好方便 verify 動作。
android software developement kit 也使用 ant 作為 build system (雖然後來又改用 grandle)
所以sdk 中有一個 folder: sdk/tools/ant, 裡面有一些寫好的 xml,
讓 developer 直接使用,不用自己再寫 build.xml
ant 雖然是為java 而做,但是他在包裝 jar 時,不會自動 copy resource file (png, wav,..etc)。
所以 jar 中用 getResource("icon.png"), 常常會出現 nullpointerexception.
因為 ant 在包 jar 時,沒有把 icon.png 也包進去。
一般來說,resource 所在位置,就是要跟使用 getResource( ) 的那個 class 在相同的目錄。
ref: http://stackoverflow.com/questions/804150/ant-compile-doesnt-copy-the-resources
就是在 jar 的 action 加上.. https://github.com/checko/androidscreencast_org/commit/fe9083623469a2e8e533179226766b84bfcd09a9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit fe9083623469a2e8e533179226766b84bfcd09a9 | |
Author: charles-chang <charles-chang@royaltek.com> | |
Date: Wed Dec 3 16:40:16 2014 +0800 | |
fix nullpointerexceotion on ImageIcon | |
diff --git a/AndroidScreencast/build.xml b/AndroidScreencast/build.xml | |
index 58c87df..42b2a32 100644 | |
--- a/AndroidScreencast/build.xml | |
+++ b/AndroidScreencast/build.xml | |
@@ -31,6 +31,10 @@ | |
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> | |
<mkdir dir="${dist}"/> | |
+ <copy todir="${build}"> | |
+ <fileset dir="${src}" | |
+ includes="**/*.png" /> | |
+ </copy> | |
<jar jarfile="${dist}/${mainjar}" basedir="${build}"/> | |
<copy file="${sdk-ddmlib}" tofile="${dist}/${ddmlib}"/> | |
</target> |
沒有留言:
張貼留言