问题
I use DexGuard and have 4 product flavors (prod, qa, dev, mock) for 2 build types (release and debug) and I don't enable DexGuard for debug builds and hence I get 4 variants (dexguardProdRelease
...dexguardMockRelease
) however, I don't want to enable DexGuard for dev and mock flavors.
I learnt about variantFilter
that Gradle provides however, I don't know how to use that command in relation to a plugin, DexGuard, in this case.
回答1:
I was able to solve like so:
//added to filter dexguard for these flavors
variantFilter { variant ->
def names = variant.flavors*.name
if(names.contains("mock") && variant.buildType.name == "release") {
variant.ignore = true
} else if (names.contains("dev") && variant.buildType.name == "release") {
variant.ignore = true
}
}
And now, Gradle doesn't show tasks like dexguardMockRelease
or dexguardDevRelease
.
I was approaching this problem incorrectly by looking at filtering out DexGuard
instead I should be looking at removing certain flavors. Here are the relevant parts of my build.gradle
:
apply plugin: 'dexguard'
...
android {
buildTypes {
release {
proguardFile getDefaultDexGuardFile('dexguard-release-aggressive.pro')
proguardFile 'dexguard-project.pro'
}
debug {
//dontshrink, dontoptimize and dontobfuscate are turned off
}
}
productFlavors {
prod {
...
}
qa {
...
}
dev {
...
}
mock {
...
}
}
//added to filter dexguard for these flavors
variantFilter { variant ->
def names = variant.flavors*.name
if(names.contains("mock") && variant.buildType.name == "release") {
variant.ignore = true
} else if (names.contains("dev") && variant.buildType.name ==
"release") {
variant.ignore = true
}
}
}
来源:https://stackoverflow.com/questions/42986599/disable-dexguard-only-for-certain-product-flavors