How to remove proguard file from inherit proguardFiles?

丶灬走出姿态 提交于 2019-12-11 02:06:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!