ProGuard 混淆、java、Google Gson 和通用集合 - 如何保留成员?
我有一个这样的类:
public class MyClass
{
private Queue<MyOtherClass> myQueue;
}
我的问题是,我无法让 ProGuard 在使用 Google Gson 序列化为 json 后保留 myQueue。发生的情况是成员名称“myQueue”被序列化为“a”。显然,反序列化就会中断。
以下是我尝试过的一些 ProGuard 配置。
-keepclassmembers class com.my.package.MyClass {
#private java.util.Queue<com.my.package.MyOtherClass> myQueue;
#private java.util.Queue<com.my.package.*> myQueue;
private java.* myQueue;
}
随着
private java.util.Queue<com.my.package.MyOtherClass> myQueue;
...ProGuard 抱怨该类未知。消息是:
注意:配置引用了未知类
java.util.Queue
'
使用
private java.* myQueue;
.... 消除了 ProGuard 警告,但是,正如我所说,成员 myQueue 不保留在 json 输出中。它被序列化为“a”。
其余相关 ProGuard 配置如下:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
#gson
-keepattributes Signature
-adaptresourcefilenames **.properties,**.gif,**.jpg,**.png,**.wav
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF
-optimizationpasses 3
-overloadaggressively
-repackageclasses ''
-allowaccessmodification
-keep public class com.my.package.MyOtherClass {
}
-keepclassmembers class com.my.package.MyOtherClass {
[a large number of private members are listed]
}
I have a class like this:
public class MyClass
{
private Queue<MyOtherClass> myQueue;
}
My problem is that I cannot get ProGuard to keep myQueue after serialization to json using Google Gson. What happens is that the member name "myQueue" is serialized as "a". Obviously, deserialization then breaks.
Here are some of the ProGuard configs I have tried.
-keepclassmembers class com.my.package.MyClass {
#private java.util.Queue<com.my.package.MyOtherClass> myQueue;
#private java.util.Queue<com.my.package.*> myQueue;
private java.* myQueue;
}
With
private java.util.Queue<com.my.package.MyOtherClass> myQueue;
...ProGuard complained that the class was unknown. The message is:
Note: the configuration refers to the unknown class
java.util.Queue<com.my.Package.MyOtherClass>'
Using
private java.* myQueue;
....gets rid of the ProGuard warning, but, as I said, the member myQueue is not kept in the json output. It is serialized as "a".
The rest of the relevant ProGuard config is as follows:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
#gson
-keepattributes Signature
-adaptresourcefilenames **.properties,**.gif,**.jpg,**.png,**.wav
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF
-optimizationpasses 3
-overloadaggressively
-repackageclasses ''
-allowaccessmodification
-keep public class com.my.package.MyOtherClass {
}
-keepclassmembers class com.my.package.MyOtherClass {
[a large number of private members are listed]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 java 类文件包含已擦除的泛型,因此 ProGuard 也期望已擦除的类型。因此,
java.util.Queue
应指定为java.util.Queue
。如果您指定
java.**
(也使用双 ** 来匹配子包中的类),则使用通配符的替代方法有效。Cfr。 ProGuard 手册
Since java class files contain erased generics, ProGuard expects erased types too. So
java.util.Queue<com.my.Package.MyOtherClass>
should be specified asjava.util.Queue
.The alternative with a wildcard works if you specify
java.**
(with double ** to match classes in subpackages too).Cfr. the ProGuard manual