问题
I have 2 buildTypes below:
debug {
...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-dont-obfuscate.pro'
...
}
inhouse.initWith(buildTypes.debug)
inhouse {
...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
println proguardFiles.toString()
...
}
I want my inhouse buildType inherited from debug (for other properties) but not to include proguard file proguard-rules-dont-obfuscate.pro as seen above. Unfortunately, after printing out the proguardFiles, it still has proguard-rules-dont-obfuscate.pro even though I didn't include it.
回答1:
I found out that proguardFiles does only proguardFiles.addAll internally. In order not to include proguard file from inherited buildTypes, I need to clear the proguardFiles list. Fortunately, I found setProguardFiles method, which does proguardFiles.clear() before setting. So the solution is add setProguardFiles(empty) before adding new proguard files.
inhouse.initWith(buildTypes.debug)
inhouse {
...
List empty = new ArrayList<String>()
setProguardFiles(empty)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
println proguardFiles.toString()
...
}
来源:https://stackoverflow.com/questions/33768222/how-to-remove-proguard-file-from-inherit-proguardfiles