ProGuard混淆,java,Google Gson和泛型集合 - 如何保持成员? [英] ProGuard obfuscation, java, Google Gson and generic collections - how to keep members?

查看:443
本文介绍了ProGuard混淆,java,Google Gson和泛型集合 - 如何保持成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的一个类:

  public class MyClass 
{
private Queue< MyOtherClass> ; myQueue中;





我的问题是我无法让ProGuard在使用json序列化后保留myQueue Google Gson。会发生什么是成员名称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< com.my .Package.MyOtherClass>'


使用

  private java。* myQueue; 

....摆脱了ProGuard的警告,但正如我所说的,myQueue成员是不保存在json输出中。它被序列化为a。



其余相关的ProGuard配置如下:

<$ p $ > code> -renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepattributes * Annotation *
#gson
-keepattributes签名
-addresourcefilenames ** .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 {
[列出大量私人会员]
}

$ b由于Java类文件包含已删除的泛型,因此ProGuard也期望擦除类型。所以 java.util.Queue< com.my.Package.MyOtherClass> 应该被指定为 java.util.Queue
$ b $ p

如果指定 java。** (使用double **来匹配类在分包装中)。



Cfr。 ProGuard手册


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]
}

解决方案

Since java class files contain erased generics, ProGuard expects erased types too. So java.util.Queue<com.my.Package.MyOtherClass> should be specified as java.util.Queue.

The alternative with a wildcard works if you specify java.** (with double ** to match classes in subpackages too).

Cfr. the ProGuard manual

这篇关于ProGuard混淆,java,Google Gson和泛型集合 - 如何保持成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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