開発およびテスト段階で頻繁にパッケージ化するのは退屈すぎるため、自動パッケージ化とリリースによって手を解放できます。前のセクションでは、fastlane のパッケージ化と公開のプロセスを分析しました。一般的に、これは少し面倒ですが、Android は、fastlane を使用してオンライン素材を自動的にパッケージ化します。オンライン素材は比較的少ないため、解決するのは非常に困難ですエラーに次ぐ問題。そこで今日は、より簡単な方法を使用して自動的にパッケージ化して公開します。
1. Gradle が自動的にパッケージ化し、Dandelion をリリースします
apply from: './dingding.gradle'//引用钉钉通知方法
def apkFileName = "${
buildTime()}_test_v${rootProject.ext.android["versionName"]}_release.apk"
def apkFilePath = "${
projectDir.absolutePath}/build/outputs/apk/test/release/${
apkFileName}"
private def uploadPGY(String filePath) {
def stdout = new ByteArrayOutputStream()
exec {
executable = 'curl'
args = ['-F', "file=@${
filePath}", '-F', "_api_key=${rootProject.ext.pgy["apiKey"]}", rootProject.ext.pgy["uploadUrl"]]
standardOutput = stdout
}
String output = stdout.toString()
def parsedJson = new groovy.json.JsonSlurper().parseText(output)
println parsedJson.data.buildQRCodeURL
println "蒲公英上传完成 版本号:" + parsedJson.data.buildVersion
println "开始发送钉钉群通知"
def downloadUrl = "https://www.pgyer.com/" + parsedJson.data.buildShortcutUrl
postDingMsg(parsedJson.data.buildQRCodeURL, downloadUrl)
}
task uploadApk(dependsOn: '打包Task名称') {
//可以从Gradle的Task列表中选取,也可以点击查看Generate Signed Bundle/Apk执行的task是什么,复制出来就好了
group = "publish"//GradleTask列表中会生成一个publish的分组,里面包含uploadApk,后续只要点击这个uploadTask任务就可以自动打包发布了
doLast {
println "打包完成: ${
apkFilePath}"
println "开始上传蒲公英"
uploadPGY(apkFilePath)
}
}
注: このファイルをアプリの build.gradle にインポートすることを忘れないでください。
2.DingTalkグループ通知
1. カスタム DingTalk ロボットを作成する
グループの右上隅にある設定ボタンをクリックします打开群设置->智能群助手->添加机器人->自定义机器人->填写机器人名称和关键词
(ここでキーワードの後に DingTalk グループ メッセージを送信する場合、メッセージの内容にキーワードが含まれている必要があります。含まれていないと送信は成功しません)
2. DingTalk グループ通知にアクセスする
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
def dingDingUrl = "https://oapi.dingtalk.com/robot/send?access_token=${rootProject.ext.dingding["accessToken"]}"
ext.postDingMsg = {
String qrcodeUrl, String downloadUrl ->
String allTips =
"版本号:V${rootProject.ext.android["versionName"]}\n" +
"下载地址:${
downloadUrl}\n"
postAll(dingDingUrl, allTips, qrcodeUrl, downloadUrl)
}
//发送到群,@所有人
def postAll(url, tips, qrcodeUrl, downloadUrl) {
JsonBuilder builder = new JsonBuilder()
builder {
msgtype 'link'
link {
title '新版本发布提醒'
text tips
messageUrl downloadUrl
picUrl qrcodeUrl
}
at {
isAtAll false //@所有人(只有text,markdown,actioncard这三种消息类型支持@功能)
}
}
String data = JsonOutput.prettyPrint(builder.toString())
postDingDing(url, data)
}
//调用接口,发送消息
def postDingDing(urlString, msg) {
if (msg == null) {
return
}
HttpURLConnection conn = null
OutputStream outputStream = null
try {
if (conn == null) {
URL url = new URL(urlString)
conn = (HttpURLConnection) url.openConnection()
}
if (conn != null) {
conn.setReadTimeout(15000)
conn.setConnectTimeout(15000)
conn.setDoOutput(true)
conn.setUseCaches(false)
conn.setRequestProperty("Content-Type", "application/json; charset=utf-8")
}
if (conn == null) {
return null
}
if (msg != null && msg.length() > 0) {
DataOutputStream dataOutputStream = new DataOutputStream(conn.getOutputStream())
byte[] t = msg.getBytes("utf-8")
dataOutputStream.write(t)
dataOutputStream.flush()
dataOutputStream.close()
int res = conn.getResponseCode()
if (res == 200) {
//成功
InputStream input = conn.getInputStream()
StringBuffer sb = new StringBuffer()
int ss
while ((ss = input.read()) != -1) {
sb.append((char) ss)
}
println "发送消息成功: ${
sb.toString()}"
} else {
println("发送消息失败: " + conn.getResponseCode())
}
}
} catch (EOFException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
} finally {
if (outputStream != null) {
try {
outputStream.close()
} catch (IOException e) {
e.printStackTrace()
}
}
if (conn != null) {
conn.disconnect()
}
}
}
新しく作成したロボットを見つけて
「コピー」を開いてフィールドWebhook地址
を確認します。accessToken
次に、使用する必要があるパラメータを設定しましょう。
群组消息类型
公式ドキュメントを参照して、ニーズに応じて調整できます。デフォルトではコードを入力しますlink
。
3. 関連する設定
ルート ディレクトリで build.gradle を開き、コードを入力します。
ext {
android = [
versionCode: 1,
versionName: "1.0.0.0"
]
pgy = [
apiKey : "xxx",
uploadUrl : "https://www.pgyer.com/apiv2/app/upload"
]
dingding = [
accessToken: "xxx",
]
}
4.効果画像:
5. SSLバグ修正
最近、コンピュータ(Windows)にアップロードしたところOpenSSL
、自動アップロード呼び出しコマンドでエラーが発生しましたcur
。
curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092013)
問題の原因:
Windows バージョンはhttps サポートを提供するために (つまり、Microsoft のセキュア チャネル、 https://msdn.microsoft.com/en-us/library/aa380123.aspx を参照) にcurl
依存しますが、Linux バージョンのcurl は次のバージョンに依存します。この 2 つのパフォーマンスには一貫性がありません。WinSSL / WinTLS
openssl
もともとウィンドウが組み込まれていたためssh
、今回はOpenSSLを再度インストールし、両者の間に競合があると推測しました。
解決:
--ssl-no-revoke
パラメータと関数をcurlに追加します关闭证书吊销检查
。修正されたcurlアップロードコードは次のようになります。
private def uploadPGY(String filePath) {
def stdout = new ByteArrayOutputStream()
exec {
executable = 'curl'
args = ['--ssl-no-revoke','-F', "file=@${
filePath}", '-F', "_api_key=${rootProject.ext.pgy["apiKey"]}", rootProject.ext.pgy["uploadUrl"]]
standardOutput = stdout
}
String output = stdout.toString()
def parsedJson = new groovy.json.JsonSlurper().parseText(output)
println parsedJson.data.buildQRCodeURL
println "蒲公英上传完成 版本号:" + parsedJson.data.buildVersion
}
6. ディンディンニュース@誰か
公式ドキュメント: https://open.dingtalk.com/document/group/robot-message-type-staff-information-in-an-enterprise
は、Dingding メッセージ @someone をサポートしています。text
、markdown
、の 3 つのメッセージ形式がありますactioncard
。そのうちの 1 つだけtext
が強調表示され、他の 2 つは強調表示されません。
//发送到群,@所有人
def postAtSomeone(url, tips, qrcodeUrl, downloadUrl) {
//发送@某人消息
JsonBuilder atPersonBuilder = new JsonBuilder()
atPersonBuilder {
msgtype 'text'
text {
content "更新内容:\n${rootProject.ext.android["versionUpdateRemark"]}\n" +
"@zfndm1v81"
}
at {
isAtAll false //@所有人
atDingtalkIds (["zfndm1v81"])//打开钉钉群,找到要@的人,复制他的钉钉号即可
//atMobiles (["135********"])
}
}
String personData = JsonOutput.prettyPrint(atPersonBuilder.toString())
postDingDing(url, personData)
}
注:
1. 公式ドキュメントでは @someone を行うには 2 つの方法があります。1 つはこの人物を構成すること钉钉userid
、もう 1 つはこの人物を構成することです手机号
。前提として、構成されたユーザー ID または携帯電話番号がこのグループに存在する必要があります。 、そうでない場合は無効になります。
2. 公式ドキュメントのユーザーIDの設定方法は以下の通りですが、テストの結果、この設定項目が無効であることが判明したため、ドキュメントの更新を忘れている可能性がありますのでatUserIds
変更する必要があります。3.に @people を必要とする情報を設定した後、それは必須です。それ以外の場合、@ は無効です。atDingtalkIds
at
在发送的消息中加上@xx
text消息
:content
@xx を接続しますmarkdown消息
|actionCard消息
:text
@xx を接続します
4.atDingtalkIds
とをatMobiles
同時に設定できます。
5. gradle の配列構成方法に注意してください([])
。groovy の文法がよくわかりません。詳しく知りたい学生は、Baidu を自分で調べてください。