7

How to handle this crash? i don't have any file Dns.kt in my project, getting crash on random user.

Dns.kt line 49 okhttp3.Dns$Companion$DnsSystem.lookup enter image description here

Fatal Exception: java.net.UnknownHostException Unable to resolve host "maps.googleapis.com": No address associated with hostname 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)

Caused by android.system.GaiException android_getaddrinfo failed: EAI_NODATA (No address associated with hostname) 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)

enter image description here

Bolt UIX
  • 5,988
  • 6
  • 31
  • 58
  • Did you got any solution for this – Ameer Jul 19 '21 at 09:23
  • no i getting error in live user app, i am unable to replicate this issue & no solution. – Bolt UIX Jul 20 '21 at 04:11
  • This might happened when you are in the app and device has no internet connection. That is how we are able to reproduce this issue, just turn off WiFi and Mobile data and app crashes after few seconds. – adi9090 Nov 11 '21 at 12:48
  • 1
    Hello, we are facing same issue. Double checking if you were able to solve it. – Akshay May 27 '22 at 20:02
  • Hey @BoltUIX, facing the same issue is happing in our Android SetTopBox project. are able to resolve it? – Tarun Sharma Dec 02 '22 at 13:32

3 Answers3

0

Try to add own dns to okhttp to catch exception. I didn't check it.

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

You can also override ip addresses for your hostnames here if you want.

Sergei K
  • 967
  • 11
  • 12
0

I had this same error. I've got past this problem and can't say for sure what exactly the cause was, but I'll share some of my observations.

In my situation, the error occurred when I opened an output stream to write some multipart html content to an http request. This is code that has been working correctly for several years, and suddenly this error started happening. This is android code that I'm running on an emulator. The URL request is using my machines host name which has an Apache tomcat server which I run in debug mode using Eclipse. I can easily set up some breakpoints on the Apache tomcat server to stop on receipt of the http request. But of course, this error is happening before the request gets to the tomcat server.

This particular error means that there is no IP address associated with my machines host name. In theory, this error means that it recognizes the host name, but that hostname doesn't have an IP address associated with it. This error message means that you have something wrong with your DNS resolution. In my case, I needed to figure out how the DNS address gets resolved to an IP address for my machines hostname. My network is configured to use a DSN server that is made available from my samba-ad-dc which is running on an UBUNTU server in my network. When I examine the status of that server, I discovered that DNS server which is part of my samba-ad-dc configuration was masked, meaning that it can't be started. I'm not certain how that DNS server became masked, but that certainly was part of my problem. I unmasked that server, so my DNS server would start up and then restarted samba-ad-dc. I would have thought that would have fixed the problem immediately, but it didn't. This is where I'm not certain what I did the caused things to work again. I rebooted my machine that was running the android studio emulator, but that too didn't fix the problem. After a certain passage of time, things suddenly started to work again. The one thing that comes to mind, is that it may have taken some time for the IP address of my hostname to be discovered. I'm not sure how the mechanism works for my hostname to IP address gets discovered and resolved. The internal samba-ad-dc is configured to forward DNS requests on to the DNS server on my router. I believe that my router caches hostnames with IP addresses and is configured to use public DNS servers for all other DNS requests. I tried eliminating the samba internal DNS altogether, but I never got that to work, so it leaves me with the impression that I need that samba internal DNS server to resolve local area hostnames. As you can perhaps see, this is where my knowledge about how the resolution actually works becomes a bit sketchy.

My advice for those running into this problem is to try and figure out how you host name gets resolve to an IP address in your network configuration. If you're dealing with local area hostnames how this works gets a little harder to figure out.

One more thing I should point out; from my windows environment I could talk to my tomcat server using my machines hostname when all this was happening. This issue only occurred from within code that was running on my Android emulator. I don't find that particularly odd, since I have my machine's hostname added to my windows "hosts" file.

Tom Rutchik
  • 1,183
  • 1
  • 12
  • 15
-5

You may need to ask for Internet permission at Android Manifest as stated on this answer: https://stackoverflow.com/a/6355961/11840668

Jorge C.M
  • 375
  • 3
  • 11
  • thank u for reply, but i already define internet permission in manifeast, i got this crash from playstore live user, can't replicate in debug – Bolt UIX Jun 21 '21 at 07:47