14

In my proguard, I have the following to keep public enums from being obfuscated.

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

My question is, does this also keep the public enum Currency in a class like this?

public class Foo {
    public enum **Currency** {PENNY, NICKLE, DIME, QUARTER};

    ...
}

If not, what do I have to add separately?

Adding the following doesn't seem to help.

-keepattributes InnerClasses

Any advice? Thanks

Szymon
  • 42,577
  • 16
  • 96
  • 114
user2062024
  • 3,541
  • 7
  • 33
  • 44
  • 1
    For Kotlin: Add the following line inside the 'proguard-rules.pro' file. -keepnames class your.package.EnumName – eyeslave Jul 10 '20 at 19:31

4 Answers4

23

You could try

-keep public enum com.stuff.TheEnclosingClass$** {
    **[] $VALUES;
    public *;
}

As shown on this answer Proguard won't keep a class member's enums

Just don't forget to put

-keepattributes InnerClasses
Community
  • 1
  • 1
Gabriel Falcone
  • 678
  • 5
  • 17
6

Can you try to tell proguard to keep the specific class:

-keep class com.xxx.Foo { *; }
Szymon
  • 42,577
  • 16
  • 96
  • 114
4

The option -keepclassmembers only keeps the class members; in this case the methods values() and valueOf(String) of all enum classes. The wild card * also matches internal classes.

If you for some reason want to preserve the inner class with its original name, you can specify:

-keep class somepackage.Foo$Currency

That should only be necessary if your application accesses the class through reflection.

Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
3

If you want to safe enum names and all fields, methods for it:

-keep enum * { *; }
Maxim Petlyuk
  • 1,014
  • 14
  • 20