How to tell ProGuard to keep private fields without specifying each field

故事扮演 提交于 2020-01-09 10:01:47

问题


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:

-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.


回答1:


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

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

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

-keepclassmembers class * {
    private <fields>;    
}


来源:https://stackoverflow.com/questions/23365021/how-to-tell-proguard-to-keep-private-fields-without-specifying-each-field

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