【问题标题】:Android proguard not workingAndroid proguard 不工作
【发布时间】:2017-11-21 13:49:10
【问题描述】:

我正在使用的 Proguard 规则如下,com.example.gym.pojo 是包名

-keep class com.example.gym.pojo.** { public *; } -keepclassmembers class com.example.gym.pojo.** { public *; }

My class `import java.util.ArrayList;
public class BulkUserResponse {

    public String message;
    public boolean success;
public ArrayList<CustomerInfo> customers;
public ArrayList<FeesInfo> fees;}` 

Proguard 规则应用后类的样子

import java.util.ArrayList;public class BulkUserResponse {
public ArrayList customers;
public ArrayList fees;
public String message;
public boolean success;}

我想要与应用 proguard 后相同的 pojo 类。因为我想解析所有的 pojo 类。我正在使用 GSON 库。

应用 proguard 后,我希望我的班级使用 public ArrayList&lt;CustomerInfo&gt; customers

提前谢谢.....

【问题讨论】:

  • 你想混淆客户的类和ArrayList?
  • public ArrayList customers; - 在 proguard 之后它有公共的 ArrayList 客户,你看不到吗?
  • 对不起我的错误。
  • 我想要公共 ArrayList 客户;应用程序后
  • 没有办法,甚至不是ProGuard的错。编译后的集合没有类型,它们只是ArrayList,没有元素类型。这就是 Java 的工作原理。

标签: java android


【解决方案1】:

我建议您使用不同的方法。 GSON 库支持使用注释进行序列化和反序列化。 你可以这样做:

public class BulkUserResponse {
    @SerializedName("message")
    @Expose
    public String message;
    @SerializedName("success")
    @Expose
    public boolean success;
    @SerializedName("customers")
    @Expose
    public ArrayList<CustomerInfo> customers;
    @SerializedName("fees")
    @Expose        
    public ArrayList<FeesInfo> fees;
}` 

这种方式如果字段名称被混淆,GSON 仍会使用您的名称序列化字段。

要保存您的通用类型(例如ArrayList&lt;FeesInfo&gt;),请使用此-keepattributes SignatureLink to original answer

【讨论】:

  • 我能够解析数据,但是当我试图读取客户类的成员时无法做到,bcz 在 progaurd 之后很难理解哪种类型的数组列表。如果我在应用 progaurd 后获得公共 ArrayList 客户,我的问题将得到解决
  • 我只添加了“-keepattributes Signature”,它对我有用
【解决方案2】:

我已经添加了

-keepattributes Signature

在 progaurd 应用我的课程后,我的样子是这样的,这是我所期待的

public class BulkUserResponse {
public ArrayList<CustomerInfo> customers;
public ArrayList<FeesInfo> fees;
public String message;
public boolean success;}

感谢 Ekalips...

【讨论】:

  • 这是我的荣幸。你可以将我的答案标记为解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-11
相关资源
最近更新 更多