美文网首页
Android 如何实现一键上传到蒲公英和钉钉、飞书群里

Android 如何实现一键上传到蒲公英和钉钉、飞书群里

作者: 小GG | 来源:发表于2023-04-06 14:54 被阅读0次

我们一般打包app上传到蒲公英,然后再在工作群里下发通知 告诉测试我们的包打好了,并且更新了什么内容。为了解决这一系列繁琐工作,今天我们就将实现方式列到下面。
本篇文章思路来源于 https://www.jianshu.com/p/fbbfeca2464a
1、在项目工程跟目录,工程的build.gradle dependencies中添加:
classpath 'com.github.centerzx:UploadApkPlugin:v***'
目前版本为:
classpath 'com.github.centerzx:UploadApkPlugin:v1.0.7'
2、配置相关平台参数
(1)上传到蒲公英的相关配置参数
以下内容配置到我们需要上传apk到model中
eg:项目名称->app->build.gradle文件中
android{ } 设置以下
(1)上传至蒲公英平台
uploadPgyParams {
apiKey = "替换为自己蒲公英账户的apiKey"
// apiKey = readProperties("PgyApiKey")
//暂时无用
appName = "TestGradlePlugin"
buildTypeName = "Release"
buildInstallType = 2
buildPassword = "zx"

 uploadApkFilePath = "E:\\Desktop\\release\\app_name-debug.apk"

}
(2)上传到钉钉的相关配置参数
buildDingParams {
accessToken = "替换为自己钉钉的token"
// accessToken = readProperties("DingAccessToken")
contentText = "最新开发测试包已经上传至蒲公英, 可以下载使用了"
contentTitle = "开发测试包"
//link类型(link)、markdown类型(markdown)、整体跳转ActionCard类型(actionCard),默认link
msgtype = "actionCard"
//如果使用markdown类型可添加参数是否@全体群人员,默认false:isAtAll = true。其他类型不支持
isAtAll = true
//存在点击时按钮的文案(link类型无)
clickTxt = "点击进行下载"
//是否单独支持发送Git记录数据,在配置了buildGitLogParams前提下有效,默认为true。link字数问题,无法支持
isSupportGitLog = true
}
(3)发送消息到飞书的相关配置参数
buildFeiShuParams {
webHookHostUrl = "https://open.feishu.cn/open-apis/bot/v2/hook/************"
// webHookHostUrl = readProperties("FeiShuWebHookHostUrl")
contentTitle = "开发测试包"
contentText = "最新开发测试包已经上传至蒲公英, 可以下载使用了"
//富文本消息(post)、消息卡片(interactive),默认post
msgtype = "post"
//是否@全体群人员,默认false:isAtAll = true
isAtAll = true
clickTxt = "点击进行下载"
//是否单独支持发送Git记录数据,在配置了buildGitLogParams前提下有效,默认为true
isSupportGitLog = true
}

(4)发送消息到企业微信群的相关配置参数
buildWeixinGroupParams {
// webHookHostUrl = readProperties("WeixinWebHookUrl")
webHookUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=************"
//文本(text)、markdown(markdown)、图文(news),默认 markdown。由于字数限制,只有markdown支持携带Git记录
msgtype = "markdown"
//如果使用文本类型(text)可添加参数是否@全体群人员,默认true:isAtAll = true。其他类型不支持
//isAtAll = true
contentTitle = "开发测试包"
contentText = "最新开发测试包已经上传至蒲公英, 可以下载使用了"
//是否单独支持发送Git记录数据,在配置了buildGitLogParams前提下有效,默认为true。只有markdown类型支持
isSupportGitLog = true
}
复制代码
(5)发送消息时携带Git提交记录相关配置参数(不配置则不携带)
buildGitLogParams {
//是否发送消息是携带Git记录日志,如果配置了这块参数才会携带Git记录,消息里面可以单独设置是否携带Git日志数据

//获取以当前时间为基准至N天之前的Git记录(限定时间范围),不填或小于等于0为全部记录,会结合数量进行获取
gitLogHistoryDayTime = 1
//显示Git记录的最大数量,值范围1~50,不填默认是10条,最大数量50条
gitLogMaxCount = 10

}

//此处参数key为 'local.properties文件中配置的 蒲公英PgyApiKey,此处可以随意命名
def readProperties(key) {
File file = rootProject.file('local.properties')
if (file.exists()) {
InputStream inputStream = file.newDataInputStream()
Properties properties = new Properties()
properties.load(inputStream)
if (properties.containsKey(key)){
return properties.getProperty(key)
}
}
}

此时在studio的右边,tasks里面会新增一个publishToThirdPlatform 命令组,里面会有3个task:ApkBuildUploadPlatformDebug、ApkBuildUploadPlatformRelease、OnlyUploadApkToPlatform,其中OnlyUploadApkToPlatform为直接上传APK操作,配置uploadApkFilePath路径后有效。gradlew或者点击运行组里面的task命令,则可直接进行编译、打包、传送、发消息等一些列操作。

1680850329420.jpg
image.png

相关文章

网友评论

      本文标题:Android 如何实现一键上传到蒲公英和钉钉、飞书群里

      本文链接:https://www.haomeiwen.com/subject/xvruddtx.html