Android:无法处理UnknownHostException [使用Retrofit 2,okhttp3,rxandroid 2] [英] Android: Unable to handle UnknownHostException [with Retrofit 2, okhttp3, rxandroid 2]

查看:1192
本文介绍了Android:无法处理UnknownHostException [使用Retrofit 2,okhttp3,rxandroid 2]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经投入生产一段时间的Android应用程序.我已经收到了Firebase的致命报告(下面是日志),但是我不清楚下次如何避免.

I've got an Android app which has been in production for some time. I've received a fatal report to Firebase (log is below) but it's not clear to me how to avoid it next time.

我在这里找到了类似的堆栈跟踪,但他们可以通过以下方式解决该问题:

I've found similar stack trace here java.net.UnknownHostException Unable to resolve host "accounts.google.com": No address associated with hostname while inserting rows in bigquery but they were able resolved it with:

<uses-permission android:name="android.permission.INTERNET" />

但这不是我的情况.

对于网络通信,我使用:

For network communication I use:

  • 改良版2
  • okhttp 3
  • 用于翻新2的rxjava2适配器

使用此设置,所有错误最终会在rx subscription中的onError函数中结束.我在所有HTTP调用中都处理UnknownHostException,但是即使我不这样做,它也应该报告非致命为最坏的情况.

With this settings all errors end up in onError function in rx subscribe. I handle UnknownHostException in all HTTP calls but even if I didn't it should report non-fatal as the worst case.

我不知道如何重现此错误.堆栈跟踪不是很有用,因为它不会将我指向应用程序的任何地方.

I don't know how to reproduce this bug. The stack trace is not very helpful as it doesn't point me anywhere to my application.

任何关于如何重现该错误的想法以及任何其他见解都将广为人知.

Any ideas on what to do to reproduce the bug and any other insights will be much apprechiated.

这是堆栈跟踪:

Exception java.net.UnknownHostException: Unable to resolve host "rest.mywebsite.com": No address associated with hostname
java.net.InetAddress.lookupHostByName (InetAddress.java:470)
java.net.InetAddress.getAllByNameImpl (InetAddress.java:252)
java.net.InetAddress.getAllByName (InetAddress.java:215)
okhttp3.Dns$1.lookup (Dns.java)
okhttp3.internal.connection.RouteSelector.hasNext (RouteSelector.java)
<OR>.connectFailed (RouteSelector.java)
<OR>.resetNextProxy (RouteSelector.java)
<OR>.resetNextInetSocketAddress (RouteSelector.java)
<OR>.getHostString (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.nextProxy (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.next (RouteSelector.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java)
<OR>.stripBody (CacheInterceptor.java)
<OR>.maybeCache (CacheInterceptor.java)
<OR>.cacheWritingResponse (CacheInterceptor.java)
<OR>.combine (CacheInterceptor.java)
<OR>.isEndToEnd (CacheInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java)
<OR>.cookieHeader (BridgeInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RetryAndFollowUpInterceptor.cancel (RetryAndFollowUpInterceptor.java)
<OR>.setCallStackTrace (RetryAndFollowUpInterceptor.java)
<OR>.intercept (RetryAndFollowUpInterceptor.java)
<OR>.createAddress (RetryAndFollowUpInterceptor.java)
<OR>.recover (RetryAndFollowUpInterceptor.java)
<OR>.isRecoverable (RetryAndFollowUpInterceptor.java)
<OR>.followUpRequest (RetryAndFollowUpInterceptor.java)
<OR>.sameConnection (RetryAndFollowUpInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.logging.HttpLoggingInterceptor.setLevel (HttpLoggingInterceptor.java)
<OR>.intercept (HttpLoggingInterceptor.java)
<OR>.isPlaintext (HttpLoggingInterceptor.java)
<OR>.bodyEncoded (HttpLoggingInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java)
okhttp3.RealCall$AsyncCall.execute (RealCall.java)
okhttp3.internal.NamedRunnable.run (NamedRunnable.java)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:588)
java.lang.Thread.run (Thread.java:818)

Caused by android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
libcore.io.Posix.android_getaddrinfo (Posix.java)
libcore.io.ForwardingOs.android_getaddrinfo (ForwardingOs.java:55)
java.net.InetAddress.lookupHostByName (InetAddress.java:451)
java.net.InetAddress.getAllByNameImpl (InetAddress.java:252)
java.net.InetAddress.getAllByName (InetAddress.java:215)
okhttp3.Dns$1.lookup (Dns.java)
okhttp3.internal.connection.RouteSelector.hasNext (RouteSelector.java)
<OR>.connectFailed (RouteSelector.java)
<OR>.resetNextProxy (RouteSelector.java)
<OR>.resetNextInetSocketAddress (RouteSelector.java)
<OR>.getHostString (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.nextProxy (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.next (RouteSelector.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java)
<OR>.stripBody (CacheInterceptor.java)
<OR>.maybeCache (CacheInterceptor.java)
<OR>.cacheWritingResponse (CacheInterceptor.java)
<OR>.combine (CacheInterceptor.java)
<OR>.isEndToEnd (CacheInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java)
<OR>.cookieHeader (BridgeInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RetryAndFollowUpInterceptor.cancel (RetryAndFollowUpInterceptor.java)
<OR>.setCallStackTrace (RetryAndFollowUpInterceptor.java)
<OR>.intercept (RetryAndFollowUpInterceptor.java)
<OR>.createAddress (RetryAndFollowUpInterceptor.java)
<OR>.recover (RetryAndFollowUpInterceptor.java)
<OR>.isRecoverable (RetryAndFollowUpInterceptor.java)
<OR>.followUpRequest (RetryAndFollowUpInterceptor.java)
<OR>.sameConnection (RetryAndFollowUpInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.logging.HttpLoggingInterceptor.setLevel (HttpLoggingInterceptor.java)
<OR>.intercept (HttpLoggingInterceptor.java)
<OR>.isPlaintext (HttpLoggingInterceptor.java)
<OR>.bodyEncoded (HttpLoggingInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java)
okhttp3.RealCall$AsyncCall.execute (RealCall.java)
okhttp3.internal.NamedRunnable.run (NamedRunnable.java)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:588)
java.lang.Thread.run (Thread.java:818)

电话已断开与网络的连接,发生在Android 6.0.1上.

The phone was disconnected from network and it happend on Android 6.0.1.

推荐答案

该问题导致嵌套的Rx调用.当我取消一个Rx呼叫的订阅时,嵌套的一个仍然存活并导致崩溃.

The problem caused a nested Rx call. When I unsubscribed from one Rx call, the nested one still lived and caused the crash.

这篇关于Android:无法处理UnknownHostException [使用Retrofit 2,okhttp3,rxandroid 2]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆