Android Proguard 和 FirebaseListAdapter 有冲突

Android Proguard & FirebaseListAdapter Are conflicting

晚上好,

我花了几个小时试图了解发生了什么。 是这样的情况:

制作了一个应用程序,在调试模式下工作正常,但发布模式在 FirebaseListAdapter 上给我错误:

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("a/");
    mAdapter = new FirebaseListAdapter<Acties>(activity, Acties.class, R.layout.list, ref) {

        @Override
        public void populateView(View v, Acties model, int position) {
            ((TextView)v.findViewById(R.id.textView1)).setText(model.getWinkel());
            ((TextView)v.findViewById(R.id.textView2)).setText(model.getBericht());
            ((TextView)v.findViewById(R.id.textView3)).setText(model.getExpdate());
        }
    };

FirebaseListAdapter 使用 Acties.class 作为吸气剂。

public class Acties {
private String bericht;
private String winkel;
private String expdate;

public Acties() {
}

public Acties(String bericht, String expdate, String winkel) {
    this.bericht = bericht;
    this.winkel = winkel;
    this.expdate = expdate;
}

public String getBericht() {
    return bericht;
}

public String getExpdate() {
    return expdate;
}

public String getWinkel() {
    return winkel;
}

}

我将每个字符串编辑为 public 而不是私有的。 (根据这个回答:

这解决了应用程序的崩溃问题,但现在我得到一个空列表。我现在可以看到 ListView,但它没有填充从我的数据库中获取的信息。

这是怎么回事?由于它的发布模式,我看不到错误..

我的类里也加了@Keep,还是不行。 (答案:

将这段代码添加到 proguard-rules 文件中:

-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**

这给了我和以前完全一样的列表,现在可以看到一个列表,但是文本视图是空的.. (答案:)

将这些规则添加到混淆器中:

-keepattributes Signature
-keepattributes *Annotation*

仍然没有任何变化.. 每个 firebase 功能都完美无缺。除了 FirebaseListAdapter/populateview 方法

感谢阅读所有这些,我现在要休息一下,很快就会回来,也许这会给我一些 "genius" 时刻

您可以添加一个指令使 ProGuard 保留 Acties 的方法和字段。只需将其添加到您的 ProGuard 文件中:

-keep class com.yourproject.Acties { *; }

其中 com.yourproject.ActiesActies class.

的全名(含包)

或者,您可以使用 @Keep 注释 Acties class,这使得 ProGuard 在应用 obfuscation/optimizations.

时保持不变