Firebase AndroidChat release build error

时光总嘲笑我的痴心妄想 提交于 2020-01-15 12:07:41

问题


I implemented a new chat feature for our app using the Firebase androidchat as a template. Everything is working great, no error whatsoever, until I try the release build.

*com.firebase.client.FirebaseException: Failed to bounce to type*

There's one similar question in stackoverflow but it appears the guy managed to fix it by correcting spelling errors within his class. I have none of those and like I said, dev build has no errors.

Here is my class:

public class Chat {

private String message;
private String author;
private String profilePic;
private Long creationDate;
private Boolean god;

// Required default constructor for Firebase object mapping
@SuppressWarnings("unused")
private Chat() {

}

public Chat(String message, String author, String profilePic, Long creationDate, Boolean god) {
    this.message = message;
    this.author = author;
    this.profilePic = profilePic;
    this.creationDate = creationDate;
    this.god = god;
}

public String getMessage() {
    return message;
}

public String getAuthor() {
    return author;
}

public String getProfilePic() {
    return profilePic;
}

public Long getCreationDate() {
    return creationDate;
}

public Boolean getGod() {
    return god;
}
}

And here's how it looks like in Firebase console http://quickscreen.me/tpBP.png

Here's the full error if it helps: http://paste.plurk.com/show/2102887/

If I remove "creationDate" it will just say "Unrecognized field message" which is also one of the class properties.

Has anyone tried the Release Build of Firebase Android Chat?


回答1:


Make sure you don't obfuscate your Chat class with Proguard. I think Proguard is the culprit because it generally only runs in release mode :

 release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
        }

And in your proguard-project.txt file :

# Basic ProGuard rules for Firebase Android SDK 2.0.0+
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
# avoid on Chat.class
-keep class yourClassPackage.Chat { *; }



回答2:


Try to clean your database or specific node, this should work if names are ok.




回答3:


Took me a couple days to finally nailed down the culprit - minifyEnabled in your gradle build file.

buildTypes {
    release {
        minifyEnabled false
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

Turn it off and problem goes away. But then apk grows 2x. I am not sure what's the alternative.



来源:https://stackoverflow.com/questions/28497673/firebase-androidchat-release-build-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!