本文介绍了如何从继承proguardFiles中删除proguard文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面有2个buildType:

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()
    ...
}

我希望我的内部buildType继承自debug(用于其他属性),但不包括proguard文件proguard-rules-dont-obfuscate.pro,如上所示.不幸的是,在打印出proguardFiles之后,即使我没有包含它,它仍然具有proguard-rules-dont-obfuscate.pro.

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.

推荐答案

我发现proguardFiles仅在内部执行proguardFiles.addAll.为了不包括继承的buildTypes中的proguard文件,我需要清除proguardFiles列表.幸运的是,我找到了setProguardFiles方法,该方法在设置之前会先执行proguardFiles.clear().因此解决方案是在添加新的proguard文件之前添加setProguardFiles(empty).

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()
    ...
}

这篇关于如何从继承proguardFiles中删除proguard文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 04:39