gpt4 book ai didi

Android minifyEnabled true for firebase

转载 作者:太空狗 更新时间:2023-10-29 16:26:25 29 4
gpt4 key购买 nike

我是 android 的初学者,我写过这样的代码。如果我启用 minifyEnabled = true,则不会触发该特定代码,而且我也不知道如何正确调试(我只能记录)。我该怎么办?

    DatabaseReference database = FirebaseDatabase.getInstance().getReference().child("ConversationUser").child(FirebaseAuth.getInstance().getUid());
database.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
ConversationUser conversationUser = dataSnapshot.getValue(ConversationUser.class);


Log.e("Chat", conversationUser.toString());
Log.e("Chat Status", conversationUser.getStatus());
String status = conversationUser.getStatus();

if (status != null && status.toLowerCase().equals("active")) {
//TODO: this never trigger if minifyEnabled = true
retrieveConversation(conversationUser.getId());
EventBus.getDefault().post(new ChatDetailAdapter.ReceiveMessage());
}
}

@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.e("ChatHelper", "onChildChanged");

ConversationUser conversationUser = dataSnapshot.getValue(ConversationUser.class);
if (conversationUser.getStatus().toLowerCase().equals("delete")) {

for(Iterator<Map.Entry<String, Conversation>> it = mainMessage.getConversations().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Conversation> entry = it.next();
if(entry.getKey().equals(conversationUser.getId())) {
it.remove();
}
}

sortConversation();
EventBus.getDefault().post(new ChatDetailAdapter.ReceiveMessage());
}
}

@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
EventBus.getDefault().post(new ChatDetailAdapter.RemoveMessage());
}

@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
EventBus.getDefault().post(new ChatDetailAdapter.ReceiveMessage());
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});

最佳答案

可能您的模型被混淆了,这就是您的代码无法正常工作的原因。要修复它,您需要将存储所有 FirebaseModels 的文件夹保留在混淆文件中。

# Firebase
-keep class com.myAppPackage.folderWhereYouSaveYourModels.** { *; }

还需要多加几行,可以查看文档:

When using Firebase Realtime Database in your app along with ProGuard you need to consider how your model objects will be serialized and deserialized after obfuscation. If you use DataSnapshot.getValue(Class) or DatabaseReference.setValue(Object) to read and write data you will need to add rules to the proguard-rules.pro file:

# Add this global rule
-keepattributes Signature

# This rule will properly ProGuard all the model classes in
# the package com.yourcompany.models. Modify to fit the structure
# of your app.
-keepclassmembers class com.yourcompany.models.** {
*;
}

希望对您有所帮助!

关于Android minifyEnabled true for firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50676718/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com