You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

应用离线时Firebase持续报错,请求协助排查解决

问题描述

应用离线时,Firebase Firestore持续抛出无法捕获的错误,恢复在线后错误停止。当前通过监听器监听Firestore集合与文档,错误日志如下:

V/NativeCrypto(26596): Read error: ssl=0xb4000074b15e4318: I/O error during system call, Software caused connection abort
V/NativeCrypto(26596): Write error: ssl=0xb4000074b15e4318: I/O error during system call, Broken pipe
W/ManagedChannelImpl(26596): [{0}] Failed to resolve name. status={1}
D/TrafficStats(26596): tagSocket(3) with statsTag=0xffffffff, statsUid=-1
W/ManagedChannelImpl(26596): [{0}] Failed to resolve name. status={1}
W/Firestore(26596): (24.9.1) [WatchStream]: (9f3395b) Stream closed with status: Status{code=UNAVAILABLE, description=End of stream or IOException, cause=null}.
V/NativeCrypto(26596): SSL shutdown failed: ssl=0xb4000074b15e4318: I/O error during system call, Success
W/Firestore(26596): (24.9.1) [WatchStream]: (9f3395b) Stream closed with status: Status{code=UNAVAILABLE, description=Unable to resolve host firestore.googleapis.com, cause=java.lang.RuntimeException: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318)
W/Firestore(26596):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
W/Firestore(26596):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
W/Firestore(26596):     at java.lang.Thread.run(Thread.java:1012)
W/Firestore(26596): Caused by: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
W/Firestore(26596):     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:124)
W/Firestore(26596):     at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
W/Firestore(26596):     at java.net.InetAddress.getAllByName(InetAddress.java:1152)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:631)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:219)
W/Firestore(26596):     ... 5 more
W/Firestore(26596): }.

该错误会重复出现,重复日志如下:

W/ManagedChannelImpl(26596): [{0}] Failed to resolve name. status={1}
W/Firestore(26596): (24.9.1) [WatchStream]: (9f3395b) Stream closed with status: Status{code=UNAVAILABLE, description=Unable to resolve host firestore.googleapis.com, cause=java.lang.RuntimeException: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318)
W/Firestore(26596):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
W/Firestore(26596):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
W/Firestore(26596):     at java.lang.Thread.run(Thread.java:1012)
W/Firestore(26596): Caused by: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
W/Firestore(26596):     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:124)
W/Firestore(26596):     at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
W/Firestore(26596):     at java.net.InetAddress.getAllByName(InetAddress.java:1152)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:631)
W/Firestore(26596):     at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:219)
W/Firestore(26596):     ... 5 more
W/Firestore(26596): }.
解决方案
  • 监听网络状态,动态启停Firestore监听器
    注册Android网络广播接收器或使用ConnectivityManager.NetworkCallback监听网络状态变化。当检测到设备离线时,主动移除Firestore的集合/文档监听器;恢复在线时,重新注册监听器。示例代码:

    // 保存监听器引用
    ListenerRegistration registration = db.collection("your-collection").addSnapshotListener(...);
    
    // 离线时移除监听器
    if (isOffline()) {
        registration.remove();
    }
    
    // 在线时重新添加监听器
    if (isOnline()) {
        registration = db.collection("your-collection").addSnapshotListener(...);
    }
    
  • 确保Firestore离线持久化已启用
    开启离线持久化后,SDK会优先使用本地缓存,减少离线状态下的无效网络请求。初始化Firestore时添加配置:

    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
            .setPersistenceEnabled(true)
            .build();
    FirebaseFirestore.getInstance().setFirestoreSettings(settings);
    
  • 过滤冗余日志输出
    如果只是不想看到这些错误日志(不影响功能),可以在Android Studio的Logcat中过滤掉ManagedChannelImpl和Firestore的WARN级别日志,或者在proguard-rules.pro中添加规则抑制相关日志。

  • 升级Firebase SDK版本
    当前使用的Firestore版本为24.9.1,尝试升级到最新稳定版,新版本可能修复了离线状态下的日志重复抛出问题。

内容的提问来源于stack exchange,提问作者Olumide

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 21:30:29