使用Python进行Android自动化打包发布

Python刚入门,都是一些基础用法。

实现的功能包括,从git更新代码->修改apk名称->上传到蒲公英->获取蒲公英返回的二维码地址

下面代码中需要蒲公英的uKey和api_key,需要去蒲公英的文档中获取(https://www.pgyer.com/doc/api#uploadApp)
这里写图片描述

# 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 \"file=@" + 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上了。

参考:
http://www.jianshu.com/p/b66d72862517

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值