Android Ant 和 Gradle 打包流程和效率對比

來源:互聯網
上載者:User

標籤:android   style   blog   c   code   tar   

一、Ant 打包:(下載ant、配置環境變數就不說了)

1、進入命令列模式,並切換到項目目錄,執行如下命令為ADT建立的項目添加ant build支援:

android update project -p . -t  "android-17"

2、build指令碼預設target是help,所以會顯示如上資訊,修改target為debug或release就可以像無ant時一樣編譯、產生以及調試了。3、使用release時  在local.properties添加簽名資訊

#keystore

key.store=xx.p12

key.alias=xxx

key.store.password=xxx

key.alias.password=xxx

4、命令列執行build.xml:    ant -buildfile build.xml


5、error 處理
> BUILD FAILED> C:\Android\android-sdk\tools\ant\build.xml:601: The following error occurred while executing this line:> C:\Android\android-sdk\tools\ant\build.xml:653: The following error occurred while executing this line:> C:\Android\android-sdk\tools\ant\build.xml:698: null returned: 1

Also, if eclipse is set to ‘build automatically‘ then this could keep popping up because eclipse will keep regenerating into the bin folder.
just run ‘ant clean release‘ instead of ‘ant release‘ when you are building this.
rm -fR $(find . -type d -name crunch|xargs)
如果遇到上述error 就執行 ant clean release
可以參考我的項目:https://github.com/mentor811/Android-Batch-Pack
二、gradle 打包1、下載gradle  1.10 配置環境變數2、配置android 環境變數 ANDROID_HOME 

3、匯出build檔案


4、修改build檔案

參考:https://github.com/umeng/umeng-muti-channel-build-tool/tree/master/Gradle

5、執行

gradle clean

gradle build


三、gradle 和 ant 的比較1、本人用起來感覺 gradle 比較苛刻

a、AndroidManifest.xml裡的注釋必須<!-- 前後必須要有空格 -->

b、中文注釋可能會有亂碼

c、各個library project 裡的 minsdk 和targetsdk 要和主工程保持一致

d、對png 圖片的格式很嚴格

e、lint

而  使用Ant 時,沒有遇到上述問題,直接就成功了。

2、gradle 會把library project 裡Androidmanifest.xml 合并到主工程,ant不會3、靈活性上 絕對是gradle,配置友盟多渠道、改包名 配置一下就ok,而ant很費勁。4、打包效率對比:

第一次執行時 之前沒有build的的項目 

gradle 2min   53   pk    ant  2min 54是 已經執行過一個build後的打包時間:

左邊gradle  右邊 ant




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.