Proguard不会保持班级成员的枚举 [英] Proguard won't keep a class member's enums
问题描述
现在我' m使用:
--keep public class com.stuff.MyConfigObject {
public *;
}
-keepclassmembers枚举* {
public static ** [] values();
public static ** valueOf(java.lang.String);
}
如果我尝试:
-keep public enum com.stuff.MyConfigObject.MyEnum
我得到一个歧义的错误:
注意:配置引用未知类'com.stuff.MyConfigObject.MyEnum'
感谢您的帮助!
代替 com.stuff.MyConfigObject $ MyEnum
Proguard 类规范期望 $
作为内部类的分隔符。
其实,对于你想要的可能最好的选择是这样的:
--keep public enum com.stuff.MyConfigObject $ ** {
** [] $ VALUES;
public *;
}
这将只保留所有枚举所需的成员
嵌套在 MyConfigObject
中,所需的成员为 $ VALUES []
数组此问题进行说明)和任何 public
枚举成员。任何其他成员(例如私人领域方法)将不被保留。
正如Jesse和我自己在评论中所指出的 - 因为您正在处理库,还必须添加 -keepAttributes
选项。参考指南:
例如,您应该至少在处理库时保留Exceptions,InnerClasses和Signature属性。 p>
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 configuration class with a bunch of member variables and some enum defines. My proguard script preserves the member variables fine, however, the enum definitions are being obfuscated. I've tried everything I can think of to force proguard to retain these internally defined and public enums, but I can't get it to work.
Right now I'm using:
-keep public class com.stuff.MyConfigObject {
public *;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
If I try:
-keep public enum com.stuff.MyConfigObject.MyEnum
I get an ambiguous error: "Note: the configuration refers to the unknown class 'com.stuff.MyConfigObject.MyEnum'"
Thanks for the help!
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 enum
s 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.
这篇关于Proguard不会保持班级成员的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!