Android Proguard&FirebaseListAdapter发生冲突 [英] Android Proguard & FirebaseListAdapter Are conflicting
问题描述
晚上好
我花了几个小时试图了解发生了什么.这是这种情况:
I have spent a couple of hours trying to understand whats going on. This is the situation:
制作了一个应用程序,在调试模式下可以正常工作,但是发布模式在FirebaseListAdapter上给了我错误:
Made an app, works fine in debug mode, but release mode gives me errors on the 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作为吸气剂.
FirebaseListAdapter uses Acties.class as getters.
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而不是private.(根据此答案: https://stackoverflow.com/a/37744290/6510329 )
I edited every string to public instead of private. (According to this answer: https://stackoverflow.com/a/37744290/6510329)
这修复了应用程序崩溃的问题,但是现在我得到了一个空列表.我现在可以看到ListView,但是其中没有充满从数据库中获取的信息.
This fixed the crash of the app, but now i got an empty list. I can see the ListView now, but it is not filled with the info grabbed from my database.
这是怎么回事?由于其释放模式,我看不到错误.
What is going on? I cannot see the error because of its release mode..
我还在我的课程中添加了@Keep,但仍然无法正常工作.(答案: https://stackoverflow.com/a/41141406/6510329 )
I have also added @Keep in my classes, and it still did not work. (Answer: https://stackoverflow.com/a/41141406/6510329)
将此代码添加到proguard-rules文件中:
Added this code to proguard-rules file:
-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.**
这给了我与以前完全相同的内容,现在可以看到一个列表,但文本视图为空.(答案: https://stackoverflow.com/a/26274623/7157263 )
Which gave me the exact same as before, a list now visible, but with empty textviews.. (Answer: https://stackoverflow.com/a/26274623/7157263)
添加了以下规则以保护自己:
Added these rules to proguard:
-keepattributes Signature
-keepattributes *Annotation*
仍然没有任何改变.每个Firebase功能都能完美运行.除了FirebaseListAdapter/populateview方法
Still nothing changed.. EVERY firebase function works perfect. EXCEPT for the FirebaseListAdapter/populateview method
感谢阅读所有这些内容,我现在要休息一下并尽快返回,也许这会给我一些天才"的时刻
Thanks for reading all of this, im going to take a break now and get back to it soon, maybe that will give me some kind of "genius" moment
推荐答案
您可以添加指令以使ProGuard保留 Acties
的方法和字段.只需将其添加到您的ProGuard文件中即可:
You can add a directive to make ProGuard preserve the methods and fields of Acties
. Just add this to your ProGuard file:
-keep class com.yourproject.Acties { *; }
其中 com.yourproject.Acties
是 Acties
类的全名(带有包).
where com.yourproject.Acties
is the full name (with package) of the Acties
class.
或者,您可以使用 @Keep
注释 Acties
类,这使ProGuard在进行模糊处理/优化时保持不变.
Alternatively, you can annotate the Acties
class with @Keep
, which makes ProGuard leave it unchanged while applying obfuscation/optimizations.
这篇关于Android Proguard&FirebaseListAdapter发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!