productFlavors can be set to use different obfuscation for different channels.
The requirement this time is that the default obfuscation in the original project remains unchanged, but a few additional files are kept in a certain channel. At this time, you can configure as follows:
android {
compileSdkVersion 28
defaultConfig {
// xxx
// 配置此参数,方可将混淆文件打包进aar
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
// 多版本打包
productFlavors {
xxx1{
// 默认
}
xxx2{
// 额外混淆
proguardFile 'keepbuildinfo.pro'
}
}
lintOptions {
abortOnError false
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
// xxx
}
Additional obfuscation file keepbuildinfo.pro:
-keep class com.xxx.xxx.BuildInfo{*;}
at this time
keepbuildinfo.pro and proguard-rules.pro will take effect in the xxx2 channel at the same time