java.net.UnknownHostException:无法解析主机“domain.com”:没有与主机名关联的地址

sco*_*out 5 android

遇到一个问题,即我的应用程序使用 https://github.com/square/okhttp - okhttp 版本 - 3.12.1 无法连接到域,即使我在 AndroidManifest.xml 中提供了互联网权限

然而,用户能够根据他们的评论在他们的设备上连接到互联网并使用其他应用程序。

目前,我无法重现该异常,因此如果以前经历过此问题的人可以帮助我更好地理解。

我目前无法升级库,因为我不想引入大的改变。

堆栈跟踪

Caused by: java.net.UnknownHostException: Unable to resolve host "domain.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$-CC.lambda$static$0(SourceFile:39)
    at okhttp3.-$$Lambda$Dns$mTkNcZf2K4euny3_jks6Cac6Az0.lookup(Unknown Source:0)
    at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(SourceFile:185)
    at okhttp3.internal.connection.RouteSelector.nextProxy(SourceFile:149)
    at okhttp3.internal.connection.RouteSelector.next(SourceFile:84)
    at okhttp3.internal.connection.StreamAllocation.findConnection(SourceFile:214)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(SourceFile:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(SourceFile:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(SourceFile:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(SourceFile:94)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(SourceFile:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(SourceFile:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at com.appdynamics.eumagent.runtime.a.a$a.intercept(SourceFile:108)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(SourceFile:264)
    at okhttp3.RealCall.execute(SourceFile:93)

Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
    at libcore.io.Linux.android_getaddrinfo(Native Method)
    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)
    ... 39 more
Run Code Online (Sandbox Code Playgroud)

Sam*_*mpa 0

我通常在使用Retrofit(使用 Okhttp 作为客户端)时遇到此错误,当设备没有任何互联网连接(WIFI 或移动数据)或我的服务器端点关闭时,就会发生此错误。自己尝试一下吧!但还有其他几个因素;例如运行时请求权限网络安全配置

希望这有帮助,兄弟。

  • 受此问题影响的用户表示,他们有互联网连接,因为他们可以使用其他应用程序。服务器端点也已启动并运行,没有错误,因此 iOS 用户不会受到影响。没有链接到 AndroidManifest 的网络安全配置规则。 (2认同)