仅在将应用发布到Google Play后才执行Firebase DatabseError-Android [英] Firebase DatabseError only after app is relesased to google play - android
问题描述
我正在制作一个使用Firebase数据库的应用程序.我的应用程序没有崩溃,直到我在Google Play上将其发布为Beta版本为止.当我发布该应用程序时,它一直崩溃,并在一行上返回com.google.firebase.database.DatabaseException.完全相同但未发布的代码不会崩溃.
I'm making an app that uses the firebase database. My app was working with no crashes, until I released it as beta on google play. When I released the app it kept crashing and returning a com.google.firebase.database.DatabaseException on one line. The exact same code but unreleased does not crash.
这是整个堆栈跟踪:
com.google.firebase.database.DatabaseException:
at com.google.android.gms.internal.zzelx.<init> (Unknown Source)
at com.google.android.gms.internal.zzelw.zzf (Unknown Source)
at com.google.android.gms.internal.zzelw.zzbx (Unknown Source)
at com.google.android.gms.internal.zzelw.zzbw (Unknown Source)
at com.google.firebase.database.DatabaseReference.zza (Unknown Source)
at com.google.firebase.database.DatabaseReference.setValue(UnknownSource)
at aheschl.studyup.NewSet$2.onClick (NewSet.java:129)
android.view.View.performClick上的
at android.view.View.performClick (View.java:6308)
at android.widget.TextView.performClick (TextView.java:11202)
at android.view.View$PerformClick.run (View.java:23969)
at android.os.Handler.handleCallback (Handler.java:751)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6816)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1563)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1451)
这是来自onClickListener的堆栈跟踪所引用的代码(带有blockquote的行是触发错误的原因):
Here is the code from the onClickListener that the stack trace references(the line with a blockquote is what is triggering the error):
CardSet newSetOfWords = new CardSet(name, words);
String id;
id = user.getUid();
DatabaseReference newReference = database.getReference(id + "/" + name);
newReference.setValue(newSetOfWords);
Intent i = new Intent(NewSet.this, TeacherView.class);
startActivity(i);
finish();
我不知道这是否有帮助,但这是我的数据库访问规则:
I don't know if this could help but here is my database access rules:
{
"rules": {
".read": "true",
".write": "auth != null"
}
}
更新-
这是proguard-rules.pro
Here's the proguard-rules.pro
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# Add this global rule
-keepattributes Signature
# This rule will properly ProGuard all the model classes in
//This is what I copied off the guide on the firebase website
# the package com.yourcompany.models. Modify to fit the structure
# of your app.
-keepclassmembers class aheschl.studyup.** {
*;
}
这是CardSet:
public class CardSet {
private String name;
private ArrayList<String> words;
public CardSet(String name, ArrayList<String> words){
this.name = name;
this.words = words;
}
protected String getName(){
return name;
}
protected ArrayList<String> getWords(){
return words;
}
}
感谢您的帮助!
推荐答案
POJO getter/setter方法必须为 public
:
The POJO getter/setter methods must be public
:
public class CardSet {
private String name;
private ArrayList<String> words;
public CardSet(String name, ArrayList<String> words){
this.name = name;
this.words = words;
}
public String getName() { // changed from protected
return name;
}
public ArrayList<String> getWords(){ // changed from protected
return words;
}
}
并且在使用 minifyEnabled
构建发行版本时,必须将Proguard配置为保留POJO类.这在 Android实时数据库安装指南中进行了描述:
And when building for release with minifyEnabled
, Proguard must be configured to retain POJO classes. This is described in the Realtime Database for Android Setup Guide:
# Add this global rule
-keepattributes Signature
# This rule will properly ProGuard all the model classes in
# the package aheschl.studyup.
-keepclassmembers class aheschl.studyup.** {
*;
}
这篇关于仅在将应用发布到Google Play后才执行Firebase DatabseError-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!