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

98,781

Solution 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

  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"/>

Solution 2

Try adding <uses-permission android:name="android.permission.INTERNET" /> to your AndroidManifest.xml file.

Solution 3

I added <uses-permission android:name="android.permission.INTERNET" /> to my manifest. I then had to restart the emulator for internet to work.

Solution 4

If you are using an emulator make sure that the mobile data is active

Solution 5

Go for AVD manager, then choose your emulator, on Actions menu click down option sign, then choose wipe data, then restart your emulator. It works for me.

Share:
98,781
David
Author by

David

Updated on July 08, 2022

Comments

  • David
    David almost 2 years

    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!