How to solve SocketException: Failed host lookup: ‘www.xyz.com’ (OS Error: No address associated with hostname, errno = 7)

Whenever I try to do an http call after about 20 seconds I get in the console the following 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:

  1. From home or though tethering from my phone: connectivity works fine on every part of the virtual device

  2. From my work network (behind the 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 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!

Answer

Adding internet permission is not only a solution.
You also have to make sure that you are online whether it is mobile or emulator

  1. Make sure you are online whether it is mobile or emulator

  2. Make sure you have given internet permission in your app’s android/app/src/main/AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET"/>

Leave a Reply

Your email address will not be published. Required fields are marked *