Error
UPDATE: Solved, it was a configuration error in Samsung Knox.
Here is another question about
SocketException: Failed host lookup: 'mydomain.com'
(OS Error: Unable to resolve host "mydomain.com": No address associated with hostname, errno = 7)
Background
My app calls my API:s, plain and simple. It used to work the other day, but after an update it stopped working and I got the error above. (The update had minor changes, should not affect this)
- Flutter app.
- Android device, Samsung Tab A (SM-515).
- The device has internet connection.
- The app has all the permissions needed to access internet.
- I am able to visit a site on the same domain using the browser.
- Restarting Wi-Fi does not help.
- Disabling Wi-Fi and using mobile network does not help.
- Restarting device does not help.
- Uninstalling the app and reinstalling it does not help.
- Uninstalling the app and installing the debug version helps, it can now access the API.
- Uninstalling the debug version and reinstalling the release version does not help, same error again.
- The exact same release version work on a different, but identical device.
- Requests are sent with
package:http/http.dart,getmethod. - The API does not have any authentication, anonymous access allowed.
- I replaced
http.dartwithpackage:dio/dio.dart, same result. - I've updated flutter and all packages and done a complete rebuild, same result.
I've seen this error before, but only temporarily. The errors are logged to Sentry, but no errors from this device are logged, implicating that the app does not have internet access at all.
It is extremely frustrating. I've spent two days on this, my last option is to factory reset the device. I don't want to do that because I want to know what the cause is and how I can prevent it from happening again.
I need help on how to debug. What can I look for in adb logcat?
Edit:
Here are the permissions set in android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Edit 2: More info in list.
Edit 3:
So I was going to try to get DNS info in the app using package:dns_client/dns_client.dart, but as I suspected the app does not access internet at all. I got the same error for the domains cloudflare-dns.com and dns.google.com.
Using InternetAddress.lookup("google.com") I got the error SocketException: Failed host lookup: 'google.com' (OS Error: No address associated with hostname, errno = 7).
Edit 4: I created a new Flutter app from scratch. And it works when adding the permissions. The error is most likely related to the permissions, but somehow the app don't get it on one specific device. Is there a permission cache on Android that persists through uninstalls and restarts?
The info about the app says it has all the permissions needed. Is it a bug in Android?
Edit 5:
Running the command adb shell dumpsys package package.name to list permissions and got this result, which shows that network access is granted.
install permissions:
android.permission.INTERNET: granted=true
android.permission.ACCESS_NETWORK_STATE: granted=true
android.permission.ACCESS_WIFI_STATE: granted=true