AndResGuard使用
项目根目录下build.gradle中,添加插件的依赖:
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.17'
}
app模块中build.gradle中,添加相关配置
APP模块中配置文件中的配置:
apply plugin: 'AndResGuard'
andResGuard {
// mappingFile = file("./resource_mapping.txt")
mappingFile = null
use7zip = true
useSign = true
// 打开这个开关,会keep住所有资源的原始路径,只混淆资源的名字
keepRoot = false
// 设置这个值,会把arsc name列混淆成相同的名字,减少string常量池的大小
fixedResName = "arg"
// 打开这个开关会合并所有哈希值相同的资源,但请不要过度依赖这个功能去除去冗余资源
mergeDuplicatedRes = true
// whiteList = [
// // for your icon
// "R.drawable.icon",
// // for fabric
// "R.string.com.crashlytics.*",
// // for google-services
// "R.string.google_app_id",
// "R.string.gcm_defaultSenderId",
// "R.string.default_web_client_id",
// "R.string.ga_trackingId",
// "R.string.firebase_database_url",
// "R.string.google_api_key",
// "R.string.google_crash_reporting_api_key"*//*
//
// ]
compressFilePattern = [
"*.png",
"*.jpg",
"*.jpeg",
"*.gif",
]
sevenzip {
artifact = 'com.tencent.mm:SevenZip:1.2.17'
//path = "/usr/local/bin/7za"
}
}
其中whiteList(白名单)中指定不需要进行混淆的资源路径规则,一些常用的三方SDK白名单设置:
AndResGuard的使用
集成完AndResGuard后,在app的gradle的tasks中,多了一个叫做andresguard的task, 下面会有resguardDebug resguardRelease点击之后运行打包
运行完之后的apk 会在app目录下的/build/output/apk/release/AndResGuard_{apk_name}/ 文件夹中找到混淆后的Apk 反编译之后会看到 res文件夹变为r,且里面的目录名称都已经是混淆过的。