android-How to connect my android emulators to internet?

1. Purpose

In this post, I would demo how to solve the DNS_PROBE_FINISHED_BAD_CONFIG internet connection failed/error problem when using android emulator to access the Internet.

2. Environment

  • MacOS or Windows
  • Android Studio 3.x
  • Last Update Date: 2021.8

3. The problem

When we try to access Internet website from inside the android emulator, we get this result:

image-20210825152407110

But I can visit this website on my host pc:

image-20210825152209435

Why did this happen? My host pc does have internet connection ,but the android emulator does not!!!

4. The solution

4.1 Solutions that not working

I have tried the following solutions ,but they are not working for me:

  • Start the emulator with the host dns
➜  emulator ./emulator -list-avds
Pixel_XL_API_30_android_11

➜  emulator ./emulator @Pixel_XL_API_30_android_11 -dns-server 8.8.8.8
[38984:135683:0825/155411.068921:ERROR:ssl_client_socket_impl.cc(1050)] handshake failed; returned -1, SSL error code 1, net_error -100
^Cemulator: Saving state on exit with session uptime 194883 ms
➜  emulator
  • wipe the emulator’s data and do a cool start

image-20210825155714076

  • Add dns entry to my host pc

All the above solutions do not work for me.

4.2 Working solution

Here is the working solution.

  • Step #1: Turn off your host PC’s wifi, just click ‘turn wi-fi off’

  • Step #2: Kill you emulator if it’s running, then open your android studio, goto Tools–AVD Manager , click Cold Boot Now button,just as follows

image-20210825175855471

​ After the cold start, the WI-FI status in the emulator should look like this:

image-20210825162239540

  • Step #3: Now turn on your host PC’s WI-FI again
  • Last Step: Test the internet connection in your emulator

image-20210825162511213

Now the emulator can access the Internet, It works!

5. Summary

In this post, I demonstrated how to fix the internet-connection-problem when using android studio’s emulators.