Java 如何告诉 ProGuard 保留私有字段而不指定每个字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/23365021/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell ProGuard to keep private fields without specifying each field
提问by cja
This is my class:
这是我的课:
package com.tools.app.holiday;
public class Holiday {  
    private String name;
    private Calendar dateFrom = Calendar.getInstance();
    private Calendar dateTo = Calendar.getInstance();
    ...
I can keep these private fields by putting the following in my ProGuard rules file:
我可以通过将以下内容放入我的 ProGuard 规则文件中来保留这些私有字段:
-keepclassmembers class com.tools.app.holiday.Holiday {
    private java.lang.String name;    
    private java.util.Calendar dateFrom;
    private java.util.Calendar dateTo;
}
But I'd prefer not to have to specify each field individually. How can I do this?
但我宁愿不必单独指定每个字段。我怎样才能做到这一点?
P.S. I stole most of this from Proguard keep classmembersbecause that question was close to what I'm asking.
PS 我从Proguard keep classmembers那里偷走了大部分内容,因为这个问题与我要问的很接近。
采纳答案by Idolon
According to ProGuard documenationthe wildcard <fields>matches any field. Thus it should be something like:
根据ProGuard 文档,通配符<fields>匹配任何字段。因此它应该是这样的:
-keepclassmembers class com.tools.app.holiday.Holiday {
    private <fields>;    
}
If you want to preserve private fields in all classes use:
如果要保留所有类中的私有字段,请使用:
-keepclassmembers class * {
    private <fields>;    
}

