标签:nta pes gem pen types 体验 local 模块 自己
第一步:在所需要打包的模块build.gradle文件中加入如下代码:
android{ buildTypes { //配置apk名称 android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = getApkName() } } } } android{ } //------------以下代码用于配置一键上传蒲公英---------------- //获取apk路径 def getApkFullPath() { return rootDir.getAbsolutePath() + "/app/build/outputs/apk/release/" + getApkName() } //此处可修改所打包的apk文件名 def getApkName() { return "update-app-example-v${android.defaultConfig.versionName}-${releaseTime()}.apk" } //设定添加打包时间 static def releaseTime() { return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) } //将密钥存在本地 防止泄露 local.properties 在Git的时候不会被上传 def readProperties(key) { File file = rootProject.file(‘local.properties‘) if (file.exists()) { InputStream inputStream = rootProject.file(‘local.properties‘).newDataInputStream() Properties properties = new Properties() properties.load(inputStream) if (properties.containsKey(key)) { return properties.getProperty(key) } } } //描述log static def getUpdateDescription() { return ‘1.修复一些bug;\n2.提升用户体验!‘ } //执行打包上传任务 task("uploadApk") { doLast { def command = "curl -F \"file=@${getApkFullPath()}\" -F \"uKey=${readProperties(‘pgyer.userKey‘)}\" -F \"_api_key=${readProperties(‘pgyer.apiKey‘)}\" -F \"buildUpdateDescription=${getUpdateDescription()}\" https://www.pgyer.com/apiv2/app/upload" try { exec { ExecSpec execSpec -> executable ‘curl‘ args = [‘-F‘, "file=@${getApkFullPath()}", ‘-F‘, "uKey=${readProperties(‘pgyer.userKey‘)}", ‘-F‘, "_api_key=${readProperties(‘pgyer.apiKey‘)}", ‘-F‘, "buildUpdateDescription=${getUpdateDescription()}", "${readProperties(‘pgyer.uploadurl‘)}"] } println "uploadApk success~" } catch (Exception e) { e.printStackTrace() } } } uploadApk.dependsOn("assembleRelease")
第二步:在项目根目录下local.properties文件中配置如下代码:
#蒲公英配置 apiKey和userKey替换成自己的就行 pgyer.apiKey=711ea731f7e59d20a6279a884a2c76f8 pgyer.userKey=61fedceea73bac2bdda4ac76kl8dbcac0 pgyer.uploadurl=https://www.pgyer.com/apiv2/app/upload
微信公众号:infree6 或者直接扫码
Android Studio如何配置CURL指令一键打包apk上传至蒲公英
标签:nta pes gem pen types 体验 local 模块 自己
原文地址:https://www.cnblogs.com/songjianzaina/p/11286945.html