Android ant自動打包腳本:自動替換友盟渠道、版本號、包名


本文最后修改時間:2014-3-10

Android項目開發時,給公司人員安裝,頻繁升級,版本號總需要改,太麻煩,跟着時間變,自動升級才方便。

Android項目開發新版時,手機上可能要裝兩個版本,一個是 老的正式版,一個是 新的開發版,想共存的話,要包名不一樣,比如chrome是com.android.chrome,而chrome beta是com.chrome.beta,自動改包名才方便。

Android項目正式發布時,發到各個市場上,要統計各個渠道的效果,所以打包要打幾十次,自動打包才方便。

所以開發了這個腳本,如下:

項目代碼:https://github.com/sinkcup/AntDemo

測試APP:http://com-163-sinkcup.qiniudn.com/io.github.sinkcup.ant-cnblogs-1.1.apk

掃描下載

截圖:

打包時自動更換友盟渠道

ant auto-release -DUMENG_CHANNEL=googlePlayStore

即會把AndroidManifest.xml中的友盟渠道替換成googlePlayStore,然后打包

ant auto-release -DUMENG_CHANNEL=xiaomiAppStore

即會打出小米應用商店的包

打包時自動更換包名

ant auto-release -Dpackage=com.example.ant.beta

把包名自動改成com.example.ant.beta,然后打包

打包時使用時間作為版本號

ant auto-debug -Dversion=time

把版本號改成時間,然后打包,效果:

versionCode是時間戳,比如1390969254

versionName是日期,比如14.1.29.1220

多個參數任意組合

ant auto-release -DUMENG_CHANNEL=googlePlayStore -Dpackage=com.example.ant.beta -Dversion=time

即打出google play的beta包,使用時間作為版本號

debug與release簽名

ant auto-debug

使用debug簽名(路徑~/.android/debug.keystore),請參考http://developer.android.com/tools/publishing/app-signing.html#debugmode

ant auto-release

使用release簽名,請修改ant.properties中的路徑、密碼等等,參考http://developer.android.com/tools/building/building-cmdline.html#ReleaseMode

如何集成到我的項目里

前提:了解Android官方文檔,在項目目錄中執行ant debug能打包,比如常見的打包步驟:

android update project -p . -s -t "android-19"
ant debug

如果ant debug打包能通過,則可以使用下面的自動打包。

下載custom_rules.xml,放到項目目錄(假設為Project1),然后執行:

ant auto-debug -Dversion=time

即可,生成的包在./bin/中。

如果想打release包,下載ant.properties,修改其中的密碼等配置,然后執行:

ant auto-release -DUMENG_CHANNEL=googlePlayStore -Dpackage=com.example.ant.beta

即可。

PS:友盟支持按渠道升級,比如cnblogs渠道升級完成還是cnblogs,googlePlayStore升級完成還是googlePlayStore。

比如

cnblogs渠道包:http://com-163-sinkcup.qiniudn.com/io.github.sinkcup.ant-cnblogs-1.1.apk

掃描下載cnblogs渠道包

google渠道包:http://com-163-sinkcup.qiniudn.com/io.github.sinkcup.ant-googlePlayStore-1.1.apk

掃描下載google渠道包

運行截圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM