使用Python進行Android自動化打包釋出
阿新 • • 發佈:2018-12-22
Python剛入門,都是一些基礎用法。
實現的功能包括,從git更新程式碼->修改apk名稱->上傳到蒲公英->獲取蒲公英返回的二維碼地址
# coding:utf-8
import os, sys, time, json
# os.system("sh buildApk.sh")
apkdir = os.getcwd() + "/build/outputs/apk/"
def gitpull():
print "**************開始更新程式碼**************"
log = os.system("git pull")
print log
print "**************程式碼更新完成**************"
# log = os.system("git log")
# print log
def uploadApk(file):
print "**************開始上傳APK**************"
uKey = "your uKey" #在這裡填入蒲公英平臺上的uKey
_api_key = "your api_key" #在這裡填入蒲公英平臺上的api_key
upload_cmd = "curl -F \"[email protected] " + file + "\" -F \"uKey=" + uKey + "\" -F \"_api_key=" + _api_key + "\" https://qiniu-storage.pgyer.com/apiv1/app/upload"
print upload_cmd
content = os.popen(upload_cmd).read()
print "上傳返回結果 -> " + content
print "**************上傳完成**************"
return content
def rename():
currentTime = time.strftime("%Y%m%d%H%M%S" , time.localtime())
appname = "mes_debug_" + currentTime + ".apk"
os.chdir(apkdir)
os.system("ls")
os.rename("app-debug.apk", appname)
return appname
def build():
print "**************開始構建APK**************"
currentTime = time.strftime("%Y%m%d%H%M%S", time.localtime())
print "當前時間:" + currentTime
os.system("gradle clean build")
appname = rename()
print "**************APK打包完成**************"
upload_result = uploadApk(apkdir + appname)
res = json.loads(upload_result.replace("\n", ""))
appQRCodeURL = str(res['data']['appQRCodeURL'])
print "**************二維碼地址 —> " + appQRCodeURL
def startBuildApk():
gitpull()
build()
startBuildApk()
有了自動打包指令碼,下一步就可以整合到Jenkins上了。