【问题标题】:Firebase DatabseError only after app is relesased to google play - androidFirebase 数据库错误仅在应用程序发布到 google play 后出现 - android
【发布时间】:2018-07-24 10:51:45
【问题描述】:

我正在制作一个使用 firebase 数据库的应用。我的应用程序运行时没有崩溃,直到我在 google play 上将它作为测试版发布。当我发布该应用程序时,它不断崩溃并在一行上返回 com.google.firebase.database.DatabaseException。完全相同但未发布的代码不会崩溃。

这是整个堆栈跟踪:

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)

这是堆栈跟踪引用的 onClickListener 中的代码(带有块引用的行是触发错误的原因):

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();

我不知道这是否有帮助,但这是我的数据库访问规则:

{
  "rules": {
      ".read": "true",
      ".write": "auth != null"
   }
 }

更新--

这是 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;
    }

}

感谢您的帮助!

【问题讨论】:

  • 您是否按照Setup Guide 中的说明配置了Proguard?您需要将命令添加到您的 proguard-rules.pro 文件以保留模型类。
  • 谢谢,我之前没有配置过。我刚刚添加了设置指南中的命令,并将发布一个新版本以查看它是否有效。
  • 不幸的是,在我添加了指南中的更改后,它仍然存在同样的问题。
  • 您可以发布您的proguard-rules.pro 文件内容吗?我仍然认为问题与您的 CardSet 类的符号的缩小和删除有关。
  • 当然,我会在我的帖子的编辑中添加它。

标签: android firebase firebase-realtime-database google-play


【解决方案1】:

POJO getter/setter 方法必须是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 类。这在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.** {
  *;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    • 2023-03-22
    • 1970-01-01
    • 2018-01-08
    相关资源
    最近更新 更多