Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

android - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...