Firebase DatabseError only after app is relesased to google play - android(Firebase DatabseError 仅在应用程序发布到 google play 后 - android)
问题描述
我正在制作一个使用 firebase 数据库的应用.我的应用程序运行时没有崩溃,直到我在 google play 上将它作为测试版发布.当我发布该应用程序时,它不断崩溃并在一行上返回 com.google.firebase.database.DatabaseException.完全相同但未发布的代码不会崩溃.
这是整个堆栈跟踪:
com.google.firebase.database.DatabaseException:在 com.google.android.gms.internal.zzelx.<init>(来源不明)在 com.google.android.gms.internal.zzelw.zzf(未知来源)在 com.google.android.gms.internal.zzelw.zzbx(未知来源)在 com.google.android.gms.internal.zzelw.zzbw(未知来源)在 com.google.firebase.database.DatabaseReference.zza(未知来源)在 com.google.firebase.database.DatabaseReference.setValue(UnknownSource)
<块引用>
at aheschl.studyup.NewSet$2.onClick (NewSet.java:129)
在 android.view.View.performClick (View.java:6308)在 android.widget.TextView.performClick (TextView.java:11202)在 android.view.View$PerformClick.run (View.java:23969)在 android.os.Handler.handleCallback (Handler.java:751)在 android.os.Handler.dispatchMessage (Handler.java:95)在 android.os.Looper.loop (Looper.java:154)在 android.app.ActivityThread.main (ActivityThread.java:6816)在 java.lang.reflect.Method.invoke (本机方法)在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1563)在 com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1451)
这是堆栈跟踪引用的 onClickListener 中的代码(带有块引用的行是触发错误的原因):
CardSet newSetOfWords = new CardSet(name, words);字符串标识;id = user.getUid();DatabaseReference newReference = database.getReference(id + "/" + name);
<块引用>
newReference.setValue(newSetOfWords);
Intent i = new Intent(NewSet.this, TeacherView.class);开始活动(一);结束();
我不知道这是否有帮助,但这是我的数据库访问规则:
<代码>{规则":{".read": "真",".write": "auth != null"}}
更新--
这是 proguard-rules.pro
# 在此处添加项目特定的 ProGuard 规则.# 您可以使用# build.gradle 中的 proguardFiles 设置.## 更多详情,请看# http://developer.android.com/guide/developing/tools/proguard.html# 如果你的项目使用带有JS的WebView,取消注释以下# 并为 JavaScript 接口指定完全限定的类名# 班级:#-keepclassmembers 类 fqcn.of.javascript.interface.for.webview {# 上市 *;#}# 取消注释以保留行号信息# 调试堆栈跟踪.#-keepattributes SourceFile,LineNumberTable# 如果你保留行号信息,取消注释# 隐藏原始源文件名.#-renamesourcefile 属性源文件# 添加这个全局规则-keepattributes 签名# 此规则将正确保护所有模型类//这是我从firebase网站上复制的指南# 包 com.yourcompany.models.修改以适应结构# 你的应用程序.-keepclassmembers 类 aheschl.studyup.** {*;}
这里是 CardSet:
公共类 CardSet {私有字符串名称;私有数组列表<字符串>字;public CardSet(String name, ArrayList words){this.name = 名称;this.words = 单词;}受保护的字符串 getName(){返回名称;}受保护的数组列表<字符串>获取单词(){回话;}}
感谢您的帮助!
POJO的getter/setter方法必须是public
:
公共类 CardSet {私有字符串名称;私有数组列表<字符串>字;public CardSet(String name, ArrayList words){this.name = 名称;this.words = 单词;}public String getName() {//从受保护更改返回名称;}公共数组列表<字符串>getWords(){//从受保护的变化回话;}}
当使用 minifyEnabled
构建发布时,必须将 Proguard 配置为保留 POJO 类.Android 实时数据库设置指南中对此进行了描述:
# 添加这个全局规则-keepattributes 签名# 此规则将正确保护所有模型类# 包 aheschl.studyup.-keepclassmembers 类 aheschl.studyup.** {*;}
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.
Here's the entire stack trace:
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)
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)
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"
}
}
UPDATE--
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.** {
*;
}
And here is 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;
}
}
Thanks for any help!
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;
}
}
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.** {
*;
}
这篇关于Firebase DatabseError 仅在应用程序发布到 google play 后 - android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Firebase DatabseError 仅在应用程序发布到 google play 后 - android
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- UITextView 内容插图 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- URL编码Swift iOS 2022-01-01