添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Fatal Exception: java.net.UnknownHostException 无法解析主机 "maps.googleapis.com"。没有与主机名相关的地址

4 人关注

我的项目中没有任何Dns.kt文件,在随机用户上出现崩溃。

Dns.kt line 49 okhttp3.Dns$Companion$DnsSystem.lookup

致命的异常: java.net.UnknownHostException 无法解析主机 "maps.googleapis.com"。没有与主机名相关的地址 java.net.Inet6AddressImpl.lookupHostByName

Fatal Exception: java.net.UnknownHostException: Unable to resolve host "maps.googleapis.com": No address associated with hostname
       at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
       at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
       at java.net.InetAddress.getAllByName(InetAddress.java:1152)
       at okhttp3.Dns$Companion$DnsSystem.lookup(Dns.kt:49)
       at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.kt:164)
       at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.kt:129)
       at okhttp3.internal.connection.RouteSelector.next(RouteSelector.kt:71)
       at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:205)
       at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
       at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
       at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
       at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)

由android.system.GaiException引起的 android_getaddrinfo失败。EAI_NODATA (没有与主机名相关的地址) okhttp3.Dns$Companion$DnsSystem.lookup

Caused by android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
       at libcore.io.Linux.android_getaddrinfo(Linux.java)
       at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
       at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
       at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
       at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
       at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
       at java.net.InetAddress.getAllByName(InetAddress.java:1152)
       at okhttp3.Dns$Companion$DnsSystem.lookup(Dns.kt:49)
       at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.kt:164)
       at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.kt:129)
       at okhttp3.internal.connection.RouteSelector.next(RouteSelector.kt:71)
       at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:205)
       at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
       at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
       at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
       at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
       at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)
    
5 个评论
你有什么办法解决这个问题吗?
no i getting error in live user app, i am unable to replicate this issue & no solution.
这可能发生在你在应用程序中,而设备没有互联网连接的情况下。这就是我们能够重现这个问题的方法,只要关闭WiFi和移动数据,几秒钟后应用程序就会崩溃。
你好,我们也面临同样的问题。仔细检查你是否能够解决这个问题。
嘿,@BoltUIX,我们的安卓SetTopBox项目也面临同样的问题,能解决吗?
android
okhttp
Bolt UIX
Bolt UIX
发布于 2021-06-20
2 个回答
Sergei K
Sergei K
发布于 2021-06-20
0 人赞同

试着在okhttp中添加自己的dns以捕捉异常。我没有检查它。

OkHttpClient.Builder()
    .dns(object : Dns {
        override fun lookup(hostname: String): List<InetAddress> {
            return try {
                Dns.SYSTEM.lookup(hostname)
            } catch (t: Throwable) {
                emptyList()