自动打包插件
- debug 包 支持自动上传蒲公英、发送钉钉通知
- release包 支持乐固加固、重新签名、walle多渠道打包,直接分发应用平台
app目录下reinforce.gradle
/**
* 打包测试环境apk 上传蒲公英 并通知钉钉
*/
task ZxAndroidDebugUpload() {
group 'ZxAndroid'
//生成debug包
dependsOn("assembleDebug")
doLast {
//上传apk文件到蒲公英平台,并发送钉钉通知
uploadApk()
}
}
/**
* 乐固加固+重新签名+美团walle渠道打包
*/
task ZxAndroidReinforceRelease() {
group 'ZxAndroid'
//生成release包
dependsOn("assembleRelease")
doLast {
//找到release文件
List<ApkFile> apkFiles = findApkFiles("release")
if (apkFiles.size() == 0) {
throw new RuntimeException("no apk files has found!")
}
File outputDir = new File(DEFAULT_APK_PATH)
println outputDir.getPath()
println "*************** start legu reinforce ***************"
for (int i = 0; i < apkFiles.size(); i++) {
ApkFile apkFile = apkFiles.get(i)
println "getAbsolutePath:"+apkFile.file.getAbsolutePath()
//乐固上传加固
reinforce(apkFile.file.getAbsolutePath(), outputDir.getAbsolutePath(), apkFile.channel)
}
//清空上一次生成的渠道包
cleanFilesPath(CHANNEL_APKS_PATH)
//寻找已加固的apk包
def reinforceApk = findApkFile(DEFAULT_APK_PATH, "_legu")
if (reinforceApk != null) {
println "--加固的APP--\n" + reinforceApk
// zipAlignApk(reinforceApk) // zip对齐
// def zipAlignApk = findApkFile(SOURCE_APK_PATH, "_zip")
//使用V2重签名
signApkV2(reinforceApk)
def signatureApk = findApkFile(SOURCE_APK_PATH, "_sign")
if (signatureApk != null) {
buildChannelApks(signatureApk) //执行多渠道打包
renameChannelApkFiles(CHANNEL_APKS_PATH) //重命名渠道包
}
}
}
}
Project目录下 gradle.properties 配置成自己的
# 蒲公英key
PGY_API_KEY=""
# 乐固加固AppId
LEGU_APP_ID = ""
# 乐固加固AppKey
LEGU_APP_KEY = ""
# 钉钉Token
DINGDING_TOKEN = ""
所需要的jar包