Firebase 运行循环中未捕获的异常 (3.0.0)

2024-02-06

我正在使用最新的 firebase(9.0.2):build.gradle:

dependencies {
     ...
     compile "com.google.firebase:firebase-database:9.0.2"
     compile 'com.google.firebase:firebase-auth:9.0.2'
}
apply plugin: 'com.google.gms.google-services'

Project build.gradle

classpath 'com.google.gms:google-services:3.0.0'

一段时间后,应用程序开始崩溃并出现以下异常:

  Fatal Exception: java.lang.RuntimeException: Uncaught exception in Firebase runloop (3.0.0). Please report to [email protected] /cdn-cgi/l/email-protection
       at com.google.android.gms.internal.zzadp$1$1.run(Unknown Source)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5274)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
Caused by java.lang.AssertionError: hardAssert failed: 
       at com.google.android.gms.internal.zzaiv.zzb(Unknown Source)
       at com.google.android.gms.internal.zzaiv.zzaN(Unknown Source)
       at com.google.android.gms.internal.zzagh.zzb(Unknown Source)
       at com.google.android.gms.internal.zzagh.<init>(Unknown Source)
       at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
       at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
       at com.google.android.gms.internal.zzadp.zza(Unknown Source)
       at com.google.android.gms.internal.zzaeu.zzic(Unknown Source)
       at com.google.android.gms.internal.zzafc.zzRy(Unknown Source)
       at com.google.android.gms.internal.zzafc.zza(Unknown Source)
       at com.google.android.gms.internal.zzafc$1.run(Unknown Source)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

在应用程序的 onCreate 中我有:

@Override
    public void onCreate() {
    ...
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}

我们还为 Firebase 创建了单例辅助类,从 Activity(同一进程中的所有活动)/Fragments 中调用:

 private FirebaseHelper() {
        mFirebaseRef = FirebaseDatabase.getInstance().getReference();
        mFirebaseAuth = FirebaseAuth.getInstance();
        mFirebaseAuth.addAuthStateListener(this);
        authentication();
    }

    public static synchronized FirebaseHelper getInstance() {
        if (mInstance == null || mInstance.getFirebaseRef() == null) {
            mInstance = new FirebaseHelper();
        }
        return mInstance;
    }

图书馆:

dependencies {
    testCompile 'junit:junit:4.12'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.6@aar') {
        transitive = true;
    }
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:support-v13:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-annotations:23.4.0'
    compile 'com.android.support:gridlayout-v7:23.4.0'
    compile 'com.google.android.gms:play-services-base:9.0.2'
    compile 'com.google.android.gms:play-services-maps:9.0.2'
    compile 'com.google.android.gms:play-services-location:9.0.2'
    compile 'com.google.android.gms:play-services-appindexing:9.0.2'
    compile 'com.google.android.gms:play-services-analytics:9.0.2'
    compile 'com.google.firebase:firebase-messaging:9.0.2'
    compile 'com.facebook.android:facebook-android-sdk:4.11.0'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.amazonaws:aws-android-sdk-core:2.2.12'
    compile 'com.amazonaws:aws-android-sdk-cognito:2.2.12'
    compile 'com.amazonaws:aws-android-sdk-s3:2.2.12'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
    compile 'io.reactivex:rxandroid:1.2.0'
    compile 'io.reactivex:rxjava:1.1.5'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'com.github.curioustechizen.android-ago:library:1.3.0'
    compile 'com.cedarsoftware:json-io:4.4.0'
    compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3@aar'
    compile 'joda-time:joda-time:2.9.3'
    compile 'com.facebook.fresco:fresco:0.10.0'
    compile 'com.facebook.fresco:imagepipeline-okhttp3:0.10.0'
    compile 'com.google.firebase:firebase-core:9.0.2'
    compile 'com.google.firebase:firebase-invites:9.0.2'
    compile 'com.google.firebase:firebase-database:9.0.1'
    compile 'com.google.firebase:firebase-auth:9.0.1'
    compile 'com.github.jd-alexander:LikeButton:0.2.0'

    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support:support-annotations:23.4.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    compile files('libs/core-3.2.1.jar')
}

UPDATE:正如克里斯蒂安在评论中提到的,事实证明这种症状还有另一个原因。我们发现了一个错误,如果您使用整数端点进行 startAt() 或 endAt() 调用,例如startAt(10),它可以触发这种缓存损坏。该错误将在下一版本的 SDK 中修复。与此同时,您也许可以使用非整数端点,例如startAt(10.001),作为解决方法。

这些症状与 Firebase 实时数据库的已知限制相符,如果您在 Android 应用程序的多个进程中启用了持久性,该限制将阻止其工作。

请注意,任何Application.onCreate()代码将为多进程 Android 应用程序中的每个进程运行,因此如果您的应用程序是多进程的,您将在多个进程中启用持久性来初始化 Firebase 数据库,这可能会导致我们的离线缓存和 HardAssert 损坏您报告的错误。

请记住,有时您的应用程序可能是多进程的,而您却没有意识到。例如,如果您使用 firebase-crash,它当前会创建一个后台进程,以便更可靠地报告崩溃,因此,如果您使用 firebase-crash,您现在拥有一个多进程应用程序。其他第三方库可能有类似的行为。

要进行测试,您可以将代码添加到 Application.onCreate() 中,例如:

System.out.println('INITIALIZING APP FROM PID: ' + android.os.Process.myPid());

如果您看到 logcat 中记录了两次(具有两个不同的 PID),则意味着您的应用程序正在使用多个进程运行,并且您遇到了我提到的限制。

作为解决方法,您可以:

  1. 修改您的应用程序,使其仅使用单个进程。
  2. 删除你的setPersistenceEnabled()您的应用程序类中的代码并将其放在仅在主进程中执行的位置。

请注意,一旦遇到硬Assert 错误,您可能需要清除应用程序数据,因为该错误表明脱机缓存已进入无效状态,因此要修复它,您必须清除它完全地。

在即将发布的版本中,我们添加了对此场景的更好检测,因此您将获得更好的错误消息。此外,firebase-crash 将来将避免产生第二个进程,这可能会使这不太可能成为问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Firebase 运行循环中未捕获的异常 (3.0.0) 的相关文章

随机推荐

  • 能否强制 AVFoundation 播放本地 .ts 文件?

    显然 AVFoundation 和 Quicktime X 可以解复用并正确播放编码 ts容器 因为 tsHTTPS 实时流媒体底层的容器 缺乏建立本地网络服务来服务 m3u8以及相关的 ts文件 我真的希望能够 说服AVURLAsset
  • 如何使用 CoreNLP 的 RegexNER 检测具有超过 1 个单词的命名实体?

    我在 CoreNLP 中使用 RegexNER 注释器 我的一些命名实体由多个单词组成 摘自我的映射文件 RAF 抑制剂 DRUG CLASS 吉尔伯特综合症 疾病 第一个被检测到 但每个单词都获得注释 DRUG CLASS 并且似乎没有办
  • 有什么办法可以将表格中的某些列居中吗?

    我广泛使用 css 格式并为表定义类 其中包含 thead tbody tfoot 的子类以及 tr th td 的另一级子类 在某些情况下 我想让表的整列具有特定样式的类 但不知道该怎么做 有没有什么方法 使用 HTML5 CSS3 其他
  • Linq .Contains 包含大集合会导致 TDS 错误

    我有点过于简单化了 因为我正在寻找通用的答案 假设我有一个这样的表设置 Parent recno int unique pk date datetime stuff varchar 50 Child parentrecno int fk P
  • Android Studio 调试错误“连接被拒绝”

    我知道以前有人问过这个问题 但我尝试了所有建议的解决方案 但还没有解决我的问题 我无法使用 Mac Yosemite 调试任何 Android studio 1 5 预览版 2 应用程序 我得到的错误是 Unable to open deb
  • 建议像 google 一样使用 postgresql trigrams 和全文搜索

    我想做一个文本搜索 我在用着PostgreSQL http www postgresql org 因为神奇的Postgis http postgis refractions net 我正在考虑使用FTS http www postgresq
  • Aarch64 上 C++11 原子的部分重新排序

    我正在看gcc 的 rmw 原子的编译器输出 https goo gl ZWLeCJ并注意到一些奇怪的事情 在 Aarch64 上 诸如 fetch add 之类的 rmw 操作可以通过宽松的负载进行部分重新排序 在 Aarch64 上 可
  • 获取磁盘上文件的所有者

    下面是我当前的宏 它运行得很好 但我想在 Cells r 10 中添加文件的所有者 这样的事情怎么可能完成呢 我找不到像 File Owner 之类的命令 Sub DoFolder Folder If Ans vbNo Then GoTo
  • Elasticsearch - 匹配字符串或空值

    我必须检查某个字段是否与特定文本匹配或为空 可以这样做吗 谢谢 您可以通过使用来实现这一点missing http www elasticsearch org guide en elasticsearch reference current
  • TypeScript 接口数组类型错误 TS2411

    我很难理解这一点 支持的索引类型有两种 字符串和数字 可以支持两种类型的索引 但限制是从数字索引返回的类型必须是从字符串索引返回的类型的子类型 虽然索引签名是描述数组和 字典 模式的强大方法 但它们还强制所有属性与其返回类型相匹配 在此示例
  • Android WebRTC 中的本地视频渲染器

    我正在使用这个库 https bintray com google webrtc google webrtc https bintray com google webrtc google webrtc 我想要实现的目标 至少在我的项目开始时
  • 共享库如何知道它所在的位置?

    我正在为 Linux 机器开发一个共享库 它是通过 rpath 相对于主可执行文件动态加载的 现在 库本身尝试相对于其位置动态加载其他库 但没有 rpath 我使用 scandir 来搜索某个文件夹中的共享库 我还不知道它们的名称 仅当工作
  • 正则表达式匹配不包含任何超过 10 个字符的单词的字符串?

    S 10 我有一个正则表达式 它将匹配任何包含 10 个字符的单词的字符串 然而我需要它的反面 一个正则表达式 仅匹配不包含 gt 10 个字符的单词的字符串 使用否定断言 S 10 S 10 匹配 10 的序列 S 它必须是更长的子序列
  • Spring:如何将属性文件中的值传递给构造函数

    我有一个MongoService类为 public class MongoService private final Mongo mongo private final String database private static fina
  • 我想在 SwiftUI 中的 TextField 添加 $ 符号

    Hi I want to add sign to a TextField when a user is typing 这是我当前的代码 ZStack alignment leading if price isEmpty Text Enter
  • fftw c2c:转换后的真实数据中缺少对称性

    最近我遇到了一些关于fftw的使用及其c2c转换的问题 参见 3d c2c fft 与 fftw 库 https stackoverflow com questions 10374656 3d c2c fft with fftw libra
  • 特征向量变换的差异:Mathematica 与 SciPy

    类似的问题之前曾在这里被问过 但似乎没有人回答我的例子 我使用 Mathematica 和 SciPy 计算矩阵 A 的特征值和特征向量 特征值一致 但特征向量则不然 1 最低 特征值 特征向量一致 2 Mathematica 和 SciP
  • Python3解析xml

    我尝试使用不同的 python3 模块和互联网上的不同文章来解析 XML 但没有成功 我有这个 XML
  • bootstrap 3 - 如何将品牌放置在导航栏的中心?

    我正在使用 Bootstrap 3 我想要一个仅包含品牌的导航栏 没有其他链接或任何其他内容 我希望品牌位于中心 我怎样才能做到这一点 以下 CSS 不起作用 navbar brand text align center css navba
  • Firebase 运行循环中未捕获的异常 (3.0.0)

    我正在使用最新的 firebase 9 0 2 build gradle dependencies compile com google firebase firebase database 9 0 2 compile com google