Proguard won't keep a class member's enums

后端 未结 2 1937
夕颜
夕颜 2020-12-15 04:54

I\'m working on a library that is distributed as a java jar, and I\'m running proguard on it in such a way as to only leave the required interfaces exposed. I have a configu

相关标签:
2条回答
  • 2020-12-15 05:11

    to keep all internal enums try this:

    -keep class * {
        public enum **;
    }
    

    it saves me from writing every of 123 enum in proguard config.

    Also, don't forget -keepAttributes if you are processing a library

    0 讨论(0)
  • 2020-12-15 05:15

    Try com.stuff.MyConfigObject$MyEnum instead. The Proguard class specification expects $ as the separator for inner classes.

    Actually, for what you want maybe the best option is something like this:

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

    This will keep only the required members for all enums nested within MyConfigObject - the required members being the $VALUES[] array (see this question for an explanation) and any public members of the enum. Any other members (e.g. private fields methods) will not be kept.


    As noted by Jesse and myself in the comments - since you are processing a library, you must also add the -keepAttributes option. From the reference guide:

    For example, you should at least keep the Exceptions, InnerClasses, and Signature attributes when processing a library.

    0 讨论(0)
提交回复
热议问题