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

yangxi_001發表於2014-03-19

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


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

執行截圖:

相關文章