问题
Whenever i try to do an http call after about 20 seconds i get in console the folowing error:
E/flutter ( 8274): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 8274): SocketException: Failed host lookup: 'flutter-project-xxxxx.firebaseio.com' (OS Error: No address associated with hostname, errno = 7)
This error happens for every method and every route i call through the app http package.
I'm developing a flutter app on Windows, using an AVD virtual device from Android Studio.
Versions: http: ^0.12.0+1 flutter: 1.0
Cases:
From home or though tethering from my phone: connectivity works fine on every part of the virtual device
From my work network (behind firewall):
Only with Android Web View i can browse the internet without any problem (i can even call the same url i use in the code and it works). I get the a connection error when using any other application (Chrome, Google Play, ecc...) in the virtual device, and specifically the "SocketException", when testing my app.
What is the difference between the calls coming from that app? Is there a way to route my app calls the same way as the ones in the webview?
Thanks!
回答1:
Adding internet permission is not only a solution.
You also have to make sure that you are online whether it is mobile or emulator
Make sure you are online whether it is mobile or emulator
Make sure you have given internet permission in your app's android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
回答2:
Try adding <uses-permission android:name="android.permission.INTERNET" />
to your AndroidManifest.xml
file.
回答3:
Had the same issue. Added uses-permission android:name="android.permission.INTERNET" to "android/app/src/main/AndroidManifest.xml". Still couldn't work, then I quit and restarted the emulator, then it worked.
回答4:
If you are using an emulator make sure that the mobile data is active
回答5:
I had that error even in Debug mode (android/app/src/debug/AndroidManifest.xml has
<uses-permission android:name="android.permission.INTERNET" />
)
I wiped data
C:\Users\username\AppData\Local\Android\Sdk\emulator> .\emulator -avd Nexus_5X_API_28 -wipe-data
then run main.dart.
回答6:
The problem is basically coming when device is trying to access any internet resources,to fix add the to AndroidManifest.xml file @android/app/src location.
回答7:
Check if the wifi is connected or not. Mine worked after restarting the wifi.
回答8:
If you are getting this error while using the flutter_socket_io
plugin, don't forget to initialize the socket i.e socketIO.init(); socketIO.connect();
before attempting to subscribe to it. I received the same error as that indicated above when I omitted it.
来源:https://stackoverflow.com/questions/54551198/how-to-solve-socketexception-failed-host-lookup-www-xyz-com-os-error-no-ad