Proguard不会保持班级成员的枚举 [英] Proguard won't keep a class member's enums

查看:112
本文介绍了Proguard不会保持班级成员的枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个作为java jar分发的库,我正在运行proguard,只能让所需的界面暴露出来。我有一个配置类有一堆成员变量和一些枚举定义。我的proguard脚本保留成员变量的罚款,但是枚举定义被模糊化。我已经尝试了我可以想到的一切,强制proguard保留这些内部定义和公开的枚举,但我无法让它工作。



现在我' 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 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.

这篇关于Proguard不会保持班级成员的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆