Android emulator not able to access the internet

I know that similar questions have been asked before, but my problem is new only after installing Android Studio 2.3, the latest version in March 2017. I have several years experience developing Android applications, and I have never encountered this problem before. After upgrading to version 2.3 of Android Studio, my emulator is no longer able to access the internet. I even uninstalled/reinstalled Android Studio 2.3 from scratch and created a new emulator, and I am still getting the same error. This is not an app problem. I can't even access the internet from Chrome, and I wasn't having this problem last week. The message that I get says that the server DNS address could not be found -- DNS_PROBE_FINISHED_BAD_CONFIG. The only thing that has changed on my computer in the last week is the new version of Android plus possibly updates to Windows 10. And yes, my computer has access to the internet. Below is an image of my emulator when I try to use Chrome to search for "Google". emulator with error message


Solution 1:

Change the DNS address of your network to 8.8.8.8 (Google's DNS) or another of your preference:

MacOSX:
  • Open "System Preferences"
  • Click on "Network"
  • Select the network which your computer is connected and click on "Advanced"
  • Select "DNS", Select the "+" button, type "8.8.8.8" (Google's DNS) or if you prefer OpenDNS, "208.67.222.222"
  • Select "Ok" and "Apply"

Windows & Linux:

https://developers.google.com/speed/public-dns/docs/using


After that close the emulator and start it again.

Solution 2:

After trying many of these solutions, I was going to just delete my current AVD and make it again, but when I clicked the down arrow on the AVD, I noticed "Cold Boot Now".

AVD Menu

On a whim I tried that. Lo and behold my emulator has internet connectivity again!

EDIT: Ok, for those saying why not just wipe data and restart. Do you reformat your PC every time you restart it? Wiping data on the emulator is just like doing a factory reset to a phone or reformatting your hard drive on your PC and reinstalling your OS. It is unnecessary unless the data is totally corrupt.

When you shut off the emulator and restart it, it is like putting your PC in hibernate or sleep mode. Memory is not wiped, it is saved.

Doing a cold boot is the same as rebooting your phone or rebooting your PC. It resets memory and lets things reload. This allows the network emulation to start with clean memory and connect properly.

So, don't wipe your data. Just cold boot. If it still doesn't work, then wipe, but save that as a last resort.

Solution 3:

I found a temporary solution on an old Stack Overflow thread at Upgraded to SDK 2.3 - now no emulators have connectivity. Note that this thread talks about Android SDK 2.3, not Android Studio 2.3. The problem seems to be that the emulator can't find the DNS my computer is currently using, and the temporary workaround is to start the emulator from the command line and specify the DNS server. Whatever problem occurred back then must have reappeared in the latest version of Android Studio.

The temporary solution outlined below fixes the problem with the emulator accessing the internet. However, it does not fix the problem that occurs when trying to run Android Device Monitor. Doing so will still make the emulator go offline as described above.

Note that there are two files named "emulator.exe" in the sdk -- one under sdk\tools and another under sdk\emulator. Either might work below, but I use the one under sdk\emulator.

The first step is to find where the SDK is located. Assuming a user name of "jdoe" and a default installation of Android Studio on Windows, the SDK is most likely in

C:\Users\jdoe\AppData\Local\Android\sdk

The second step is to determine the name of the AVD (emulator) that you want to run. The command

C:\Users\jdoe\AppData\Local\Android\sdk\emulator\emulator.exe -list-avds

will show the names of your AVDs. On my computer, it shows only one, Nexus_5X_API_25.

To start the emulator from the command line with a specified DNS server, use something like the following:

C:\Users\jdoe\AppData\Local\Android\sdk\emulator\emulator.exe -avd Nexus_5X_API_25 -dns-server 8.8.8.8

In this case, 8.8.8.8 is a Google public domain name server.

The above commands can be shortened if you create appropriate environment variables and edit your PATH environment variable, but I recommend caution when doing so.

Solution 4:

[UPDATE 2022] for Mac Users

For NOT Apple Silicon users

  1. System Preferences
  2. Network
  3. WiFi > Select Advanced
  4. From Advanced Choose DNS tab
  5. Add DNS Server 8.8.8.8
  6. Emulator must be restarted after DNS Server has been added (Thanks to @kapusch)

For Apple Silicon users

as per @bourdier-jonathan You can fix the Silicon issue here: Emulator appearing offline on M1 Mac after the last update of arm64-v8a

By replacing the AVD system images you have downloaded with the r02 images. Because It appears r03, r04, and r05 all don't work on m1

Solution 5:

Updating my WIFI adapter to resolve DNS on 8.8.8.8 solved the issue for me. It started to happen after an Apple update which messed up the DNS address.

enter image description here