Proguard混淆导致java.lang.IllegalArgumentException:类声明多个名为“a”的JSON字段。 [英] Proguard obfuscation results in java.lang.IllegalArgumentException: class declares multiple JSON fields named "a"

查看:180
本文介绍了Proguard混淆导致java.lang.IllegalArgumentException:类声明多个名为“a”的JSON字段。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动我的应用程序时记录了两个错误,但仅在混淆之后。没有混淆就没有错误。



除非我被误导,否则错误如下所示:


class Property声明了多个名为a的JSON字段


,对于类PropertyDefinition也是如此。 b

  05/18 03:33:19.465 java.lang.IllegalArgumentException:class PropertyDefinition声明多个名为a:
com.google.gson的JSON字段。 internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:122)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
com.google.gson.Gson。 getAdapter(Gson.java:349)
com.google.gson.Gson.toJson(Gson.java:574)
com.google.gson.Gson.toJson(Gson.java:561)
com.google.gson.Gson.toJson(Gson.java:516)
com.google.gson.Gson.toJson(Gson.java:496)
Property.a(SourceFile:210) <请参阅以下代码中的注释,注意此代码行> (源文件:339)

05/18 03:33:19.479 java.lang.IllegalArgumentException:class属性声明多个名为a的JSON字段:
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:122)
com。 google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
com.google.gson.Gson.getAdapter(Gson.java:349)
com.google.gson.Gson。 fromJson(Gson.java:790)
com.google.gson.Gson.fromJson(Gson.java:757)
com.google.gson.Gson.fromJson(Gson.java:706)
com.google.gson.Gson.fromJson(Gson.java:678)
Property.a(SourceFile:75)<请参阅以下代码中的注释,注意此代码行>
bj.a(SourceFile:44)
aA。< init>(SourceFile:339)

以下是与几乎相同的错误之一相关的混淆映射部分。我在这里和上面未混淆类名Property。我没有看到问题。

  mypackage.Property:
我没有进一步的混淆经验,所以我不知道要找什么。 mypackage.PropertyDefinition rootElement - > a
java.util.HashMap indexById - > a
java.util.HashMap indexByKey - > b
long nntgID - > a
43:54:boolean equals(java.lang.Object) - >等于
60:64:int hashCode() - > hashCode
68:84:布尔检查() - > a
88:88:java.lang.String getFileName() - >
92:92:java.lang.String getDirectory() - > b
101:102:java.lang.String getVersion() - > c
107:107:java.util.HashMap getIdIndex() - > a
112:112:java.util.HashMap getKeyIndex() - > b
122:122:long getNntgID() - > a
126:127:void setNntgID(long) - > a
142:147:void setRootElement(mypackage.PropertyDefinition) - >
150:150:mypackage.PropertyDefinition getPropertyDefinitionById(java.lang.String) - >
154:154:mypackage.PropertyDefinition getPropertyDefinitionByKey(java.lang.String) - > b
162:168:java.lang.String toString() - > toString
210:214:void toFile() - > a

顺便说一下,我已经在我的Proguard配置中使用了这部分内容:

  -keep class com.google.gson ** {*; } 
-keepclassmembers class com.google.gson ** {
*;
}

关于从何处开始排除故障的建议?
您似乎在您的proguard-project.txt中指定了ProGuard选项 -overloadaggressively 。它将字段名称和方法名称重载为相同的混淆名称,例如'a',只要字段和方法的签名是不同的。它对于类文件是有效的,但是GSON显然不喜欢它,所以你应该避开这个选项。


Upon starting up my app logs two errors, but only after obfuscation. Without obfuscation there are no errors.

Unless I'm being misled, the errors are like:

class Property declares multiple JSON fields named a

and same for class PropertyDefinition.

05/18 03:33:19.465  java.lang.IllegalArgumentException: class PropertyDefinition declares multiple JSON fields named a:  
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:122)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
com.google.gson.Gson.getAdapter(Gson.java:349)
com.google.gson.Gson.toJson(Gson.java:574)
com.google.gson.Gson.toJson(Gson.java:561)
com.google.gson.Gson.toJson(Gson.java:516)
com.google.gson.Gson.toJson(Gson.java:496)
Property.a(SourceFile:210) <see comment in code below noting this code line>
Property.a(SourceFile:68)
bj.a(SourceFile:44)
aA.<init>(SourceFile:339)

05/18 03:33:19.479  java.lang.IllegalArgumentException: class Property declares multiple JSON fields named a:  
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:122)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
com.google.gson.Gson.getAdapter(Gson.java:349)
com.google.gson.Gson.fromJson(Gson.java:790)
com.google.gson.Gson.fromJson(Gson.java:757)
com.google.gson.Gson.fromJson(Gson.java:706)
com.google.gson.Gson.fromJson(Gson.java:678)
Property.a(SourceFile:75) <see comment in code below noting this code line>
bj.a(SourceFile:44)
aA.<init>(SourceFile:339)

Here is the section of the obfuscation map relevant to one of the nearly identical errors. I unobfuscated the class name "Property" here and above. I don't see the problem. I have no further experience with obfuscation so I don't know what to look for.

mypackage.Property:
    mypackage.PropertyDefinition rootElement -> a
    java.util.HashMap indexById -> a
    java.util.HashMap indexByKey -> b
    long nntgID -> a
    43:54:boolean equals(java.lang.Object) -> equals
    60:64:int hashCode() -> hashCode
    68:84:boolean check() -> a
    88:88:java.lang.String getFileName() -> a
    92:92:java.lang.String getDirectory() -> b
    101:102:java.lang.String getVersion() -> c
    107:107:java.util.HashMap getIdIndex() -> a
    112:112:java.util.HashMap getKeyIndex() -> b
    122:122:long getNntgID() -> a
    126:127:void setNntgID(long) -> a
    142:147:void setRootElement(mypackage.PropertyDefinition) -> a
    150:150:mypackage.PropertyDefinition getPropertyDefinitionById(java.lang.String) -> a
    154:154:mypackage.PropertyDefinition getPropertyDefinitionByKey(java.lang.String) -> b
    162:168:java.lang.String toString() -> toString
    210:214:void toFile() -> a

BTW, I have this section in my Proguard config already:

-keep class com.google.gson** { *; }
-keepclassmembers class com.google.gson** {
   *;
}

Any suggestions on where to start troubleshooting?

解决方案

You seem to be specifying the ProGuard option -overloadaggressively in your proguard-project.txt. It overloads field names and method names to the same obfuscated names, e.g. 'a', as long as the signatures of the fields and methods are different. It's valid for class files, but GSON clearly doesn't like it, so you should avoid the option.

这篇关于Proguard混淆导致java.lang.IllegalArgumentException:类声明多个名为“a”的JSON字段。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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