Firebase/Android - 经常丢失数据库连接

Firebase/Android - Regularly losing database connection

我遵循了 Firebase 身份验证和数据库的文档。

全新安装后一切正常:

用户可以注册或登录,数据按应有的方式检索,按应有的方式写入,超快,超干净。耶。

然后,在通过 android Studio 重新启动几次后,数据库的东西不再工作了。重新启动的次数各不相同,我找不到规则等。如果我卸载并重新安装 apk(仍然通过 Android Studio),它会再次运行。

我正在监控身份验证状态,用户保持登录状态,也根本没有 firebase 错误。

我得到了很多 E/DynamiteModule: Failed to load module descriptor class: 但显然这不是错误(只是提到它是因为我得到了 20 多行连续的“错误”。

知道我应该从哪里开始寻找吗?

app.gradle

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        ...
        minSdkVersion 15
        targetSdkVersion 23
        ...
    }
    ...
}
...
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.firebase:firebase-core:9.0.1'
    compile 'com.google.firebase:firebase-database:9.0.1'
    compile 'com.google.firebase:firebase-storage:9.0.1'
    compile 'com.google.firebase:firebase-auth:9.0.1'
    compile 'com.google.firebase:firebase-messaging:9.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
    compile 'cn.pedant.sweetalert:library:1.3'
    testCompile 'junit:junit:4.12'
}

Firebase 数据库规则

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

听起来您可能遇到了由身份验证令牌刷新失败引起的已知问题 discussed here. Try enabling debug level logging using FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG) and compare the output with the samples included in the discussion linked above. In particular, look for "Error fetching token: An internal error has occured. [ Internal error. ]". If you see that, follow the instructions provided here 以修复您的 google-services.json 文件。