版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Mr_theSun/article/details/86504112
Github:https://github.com/shwenzhang/AndResGuard
下面是项目内配置:
新建一个and_res_guard.gradle(与app的build.gradle同一级别)
apply plugin: 'AndResGuard'
andResGuard {
// mappingFile = file("./resource_mapping.txt")
mappingFile = null
//Do NOT enable 7zip compression(use7zip) when you distribute your APP on Google
//Play. It'll prevent the file-by-file patch when updating your APP.
use7zip = false
useSign = true
// it will keep the origin path of your resources when it's true
keepRoot = false
whiteList = [
// your icon
//表情
"R.drawable.face00",
"R.drawable.face01",
"R.drawable.face02",
"R.drawable.face03",
// 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",
//Do NOT add resource.asrc into compressFilePattern unless the app size is really matter //to you.
]
sevenzip {
artifact = 'com.tencent.mm:SevenZip:1.2.15'
//path = "/usr/local/bin/7za"
}
/**
* Optional: if finalApkBackupPath is null, AndResGuard will overwrite final apk
* to the path which assemble[Task] write to
**/
// finalApkBackupPath = "${project.rootDir}/final.apk"
/**
* Optional: Specifies the name of the message digest algorithm to user when digesting the entries of JAR file
* Only works in V1signing, default value is "SHA-1"
**/
// digestalg = "SHA-256"
}
然后在app的build.gradle下添加 apply from: 'and_res_guard.gradle'
注意:
如果代码中使用了
int resId = application.getResources().getIdentifier(res_name, "drawable", application.getPackageName());
是获取不到的,需要将res_name的图片加入白名单,就像我上面的配置
配置完成就可以打包了:
先build一下,打开下图
编译resguardRelease