Proguard不會保留一個類成員的enums。

[英]Proguard won't keep a class member's enums


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.

我正在開發一個作為java jar分發的庫,並且我正在以這樣一種方式運行proguard,它只會讓所需要的接口暴露出來。我有一個帶有一些成員變量的配置類和一些enum定義。我的proguard腳本保留了成員變量,但是,enum定義被混淆了。我已經嘗試了所有我能想到的方法來強迫proguard保留這些內部定義的和公共的enums,但是我不能讓它工作。

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'"

我得到了一個模糊的錯誤:“注意:配置是指未知類的com. stuff.myconfigobjectmyenum”。

Thanks for the help!

謝謝你的幫助!

1 个解决方案

#1


32  

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

com.stuff試試。MyConfigObject MyEnum而不是美元。Proguard類規范期望$作為內部類的分隔符。

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.

這將只保留在MyConfigObject內嵌套的所有枚舉的必需成員——所需的成員是$VALUES[]數組(請參見這個問題以獲得解釋)和枚舉的任何公共成員。任何其他成員(如私有域方法)將不被保留。


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:

正如Jesse和我在評論中提到的——既然你正在處理一個庫,你還必須添加- keepattributes選項。從參考指南:

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

例如,在處理庫時,至少應該保留異常、內部類和簽名屬性。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/06/08/720906ac86015c4590e19a3dc091b2f9.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com