多渠道打包神奇 https://github.com/mcxiaoke/packer-ng-plugin
自我感觉比较好用的多渠道打包 packer-ng-plugin
一下是AndResGuard 与 packer-ng-plugin 打包配置
1、在项目的build.gradle中配置添加
dependencies {
classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.20'
classpath 'com.mcxiaoke.packer-ng:plugin:2.0.1'
}
2、AndResGuard 脚本 res_guard.gradle
apply plugin: 'AndResGuard'
andResGuard {
// mappingFile = file("./resource_mapping.txt")
mappingFile = null
// 当你使用v2签名的时候,7zip压缩是无法生效的。
use7zip = false
useSign = true
// 打开这个开关,会keep住所有资源的原始路径,只混淆资源的名字
keepRoot = false
whiteList = [
// for your icon
"R.mipmap.ic_launcher",
//react-native
"R.drawable.src_res_*",
]
compressFilePattern = [
"*.png",
"*.jpg",
"*.jpeg",
"*.gif",
"resources.arsc"
]
sevenzip {
artifact = 'com.tencent.mm:SevenZip:1.2.20'
}
}
3、packer-ng-plugin 脚本 package.gradle
project.afterEvaluate {
//在Release后执行资源混淆,然后多渠道打包
//打包命令 ./gradlew resguardRelease
tasks.getByName("resguardRelease") {
it.doLast {
println 'channel package task begin'
def oldName = "app-release"
def fileName = oldName + "_aligned_signed.apk"
def rApk = new File(rootProject.getRootDir().getAbsolutePath() + "/app/build/outputs/apk/release/AndResGuard_" + oldName + "/" + fileName)
println("压缩资源生成apk文件的位置------" + rApk)
if (rApk.exists()) {
println 'resGuard apk exits begin channel package'
packageChannel(rApk.absolutePath)
println '多渠道打包完成,请到 ' + rootProject.getRootDir().getAbsolutePath() + '/build/apk/archives 目录下获取.....'
}else{
println '文件不存在'
}
}
}
}
def packageChannel(String releaseApk) {
try {
def stdout = new ByteArrayOutputStream()
exec {
def command = [
'java', '-jar', rootProject.getRootDir().getAbsolutePath() + '/packer-ng-2.0.1.jar',
'generate', '--channels=@' + rootProject.getRootDir().getAbsolutePath() + '/channel.txt',
'--output=' + rootProject.getRootDir().getAbsolutePath() + '/build/apk/archives',
releaseApk
]
println("执行打包命令:" + command)
//执行python脚本打多渠道包
commandLine command
standardOutput = stdout
}
return stdout.toString().trim()
} catch (ignored) {
println "##未知错误##"+ignored
return "UnKnown"
}
}
4、channel.txt配置
xiaomi
official
huawei
vivo
oppo
yingyongbao
5、在app build.gradle中添加脚本
// android res guard 资源混淆脚本
apply from: 'res_guard.gradle'
// 多渠道打包脚本
apply from: 'package.gradle'
packer-ng-2.0.1.jar 下载地址 https://github.com/mcxiaoke/packer-ng-plugin/tree/master/tools
在项目目录下运行命令打包
./gradlew resguardRelease
网友评论