Android minifyEnabled true for firebase

标签 android firebase

我是 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/

相关文章:

android - android中的位图内存不足错误...

android - Jetpack Compose pointerInput detectTapGestures 设置onLongPress超时?

android - 如何在一个activity中实现2个或多个recyIclerview

database - 该文档不存在,不会出现在查询或快照中,但结构相同的文档有效

firebase - 错误在Flutter中检索Firebase集合数时?

Javascript:将数组数组拆分为多个数组

firebase - flutterfire : The term 'flutterfire' is not recognized as the name of a cmdlet, 函数、脚本文件或可运行程序

android - 我无法通过单击 imageButtom 删除带有自定义适配器的 ListView 中的正确项目

android - VideoView 仅在 Galaxy s4 上不循环播放视频

javascript - Firebase Realtime Database - on event - Javascript Deltasnapshot 和 Android Java DataSnapshot 的区别