AGP7.0以上引用AndResGuard有坑 记录下
在项目的build.gradle中添加如下
buildscript {
ext.kotlin_version = "1.4.31"
repositories {
google()
jcenter()
maven {
url "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:7.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath "com.bytedance.android:aabresguard-plugin:0.1.0"
classpath 'io.github.leon406:AndResGuard-gradle-plugin:1.2.23'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
在app目录下新建脚本and_res_guard.gradle
apply plugin: 'AndResGuard'
andResGuard {
//mappingFile = file("./resource_mapping.txt")
mappingFile = null
use7zip = true
useSign = true
keepRoot = false
compressFilePattern = [
"*.png",
"*.jpg",
"*.jpeg",
"*.gif",
"*.xml",
"*.json",
"*.html",
// "assets.arsc",
"resources.arsc"
]
whiteList = [
// your icon
"R.mipmap.ic_launcher",
"R.mipmap.ic_launcher_round",
// for fabric
"R.string.com.crashlytics.*",
// for umeng update
"R.string.tb_*",
"R.layout.tb_*",
"R.drawable.tb_*",
"R.drawable.u1*",
"R.drawable.u2*",
"R.color.tb_*",
// umeng share for sina
"R.drawable.sina*",
// for google-services.json
"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",
//友盟
"R.string.umeng*",
"R.string.UM*",
"R.layout.umeng*",
"R.drawable.umeng*",
"R.id.umeng*",
"R.anim.umeng*",
"R.color.umeng*",
"R.style.*UM*",
"R.style.umeng*",
//融云
"R.drawable.u*",
"R.drawable.rc_*",
"R.string.rc_*",
"R.layout.rc_*",
"R.color.rc_*",
"R.id.rc_*",
"R.style.rc_*",
"R.dimen.rc_*",
"R.array.rc_*"
]
sevenzip {
artifact = 'com.tencent.mm:SevenZip:1.2.10'
//path = "/usr/local/bin/7za"
}
/**
* 可选: 如果不设置则会默认覆盖assemble输出的apk
**/
//finalApkBackupPath = "${project.rootDir}/final.apk"
}
在app/build.gradle中引用第二步的脚本
apply from: 'and_res_guard.gradle'
其他环境配置
grade:gradle-7.3.3-bin.zip
classpath "com.android.tools.build:gradle:7.2.2"
jdk:11
执行编译 附上demo:demo