9

How can I tell proguard to keep my classmembers?

I need them for JSON compatibility...

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 already tried, but it doesnt work...

-keepclassmembers class com.tools.app.holiday.Holiday 

-keepclassmembers class com.tools.app.holiday.Holiday *{
    private String name;    
    private Calendar dateFrom;
    private Calendar dateTo;
}

I also implemented serialisable and did:

-keepclassmembers class * implements java.io.Serializable {

But it all doesn't keep my member names. Proguard always changes ist to a, b, c :-( What am I missing?

Tobias
  • 7,282
  • 6
  • 63
  • 85

1 Answers1

14

All class names must be fully qualified:

-keepclassmembers class com.tools.app.holiday.Holiday {
    private java.lang.String name;    
    private java.util.Calendar dateFrom;
    private java.util.Calendar dateTo;
}

By default, ProGuard even prints out messages if you forget this.

Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • 1
    Do you have to specify each field explicitly? Please see http://stackoverflow.com/questions/23365021/how-to-tell-proguard-to-keep-private-fields-without-specifying-each-field – cja Apr 29 '14 at 12:51