如何告诉ProGuard保留私有字段而不指定每个字段

时间:2021-06-10 14:21:48

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 classmembers because that question was close to what I'm asking.

附:我偷走了Proguard的大部分内容,因为这个问题接近于我所要求的问题。

1 个解决方案

#1


42  

According to ProGuard documenation the wildcard <fields> matches any field. Thus it should be something like:

根据ProGuard文档,通配符 匹配任何字段。因此它应该是这样的:

-keepclassmembers class com.tools.app.holiday.Holiday {
    private <fields>;    
}

If you want to preserve private fields in all classes use:

如果要保留所有类中的私有字段,请使用:

-keepclassmembers class * {
    private <fields>;    
}

#1


42  

According to ProGuard documenation the wildcard <fields> matches any field. Thus it should be something like:

根据ProGuard文档,通配符 匹配任何字段。因此它应该是这样的:

-keepclassmembers class com.tools.app.holiday.Holiday {
    private <fields>;    
}

If you want to preserve private fields in all classes use:

如果要保留所有类中的私有字段,请使用:

-keepclassmembers class * {
    private <fields>;    
}