Android emulator not able to access the internet

2019-01-16 06:12发布

问题:

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

回答1:

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.



回答2:

For me I just change the DNS address of my network to 8.8.8.8 and worked:

How to do it on a 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"
  • Select "Ok" and "Apply"


How to do it on Windows & Linux:

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


After that close the emulator and start it again.



回答3:

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.



回答4:

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

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



回答5:

I experienced this same issue after upgrade. Upon opening the Chrome browser in the emulator, google.com could no longer be reached.

I found a post on SO that suggested the problem was with the emulator trying to use a disconnected network adapter. For me the problem was occurring when I was connected to a LAN. Disabling the wireless LAN adapter fixed the issue.

To disable the adapter:

  1. Navigate to Network connections
  2. Find the adapter
  3. Right click and choose disable


回答6:

Simply open the AVD Manager and wipe the data of that emulator works for me.



回答7:

I am also facing the same problem, but I am trying to solve the problem using various posts. Today I discovered this problem. Your computer configuration is most likely the problemm, not Android Studio and the Android Emulator.

The problem is coming from your Network setup. Just set the Primary DNS Server to 8.8.8.8, which will solve the problem.



回答8:

This happend to me when the emulator froze and I had to kill the process. The signal icon always showed the small "x" as in the screenshot and no internet connection was successful.

The only thing that helped was uninstalling and reinstalling the emulator (not the AVD images)

In Android Studio:

Tools-> Android -> SDK Manager Uncheck "Android Emulator" and let it uninstall then check again and let it install again.



回答9:

This was a problem for me last time the emulator updated itself and back then disabling other network adapters fixed it. Now it's cropped up again but the only adapter that is enabled is a single wifi one so I have nothing to disable.

The issue only reappeared after I updated via a prompt the emulator tools to 26.1.1. I uninstalled and reinstalled the emulator via the SDK Tools update tab and thankfully the only option when installing again right now is to install 26.0.3 (which seems to be working okay).

Moral of the story is to be very wary of emulator updates.



回答10:

Open Android emulator and go to the Extended Controls. Then go to the setting => proxy(Tab) and unchecked "Use Android studuio HTTP proxy setting".



回答11:

For me the problem was caused when I took my laptop home without restarting the emulator. From what I have read, when the emulator starts up it reads your PC's DNS settings and uses them. When I was on my home network, my work DNS settings were failing.
So yeah. Just restarting the emulator solved my problem.



回答12:

if android browser can access internet you can run emulator from terminal by this command

go to SDK path then

$ /tools/emulator -avd Nexus_5X_API_23 -netdelay none -netspeed full

it solve your internet problem...



回答13:

I've resolved wiping data from AVD Manager



回答14:

After 10 days of trouble, I just deleted everything from C:\Android\.android\ and deleted all created AVDs. Now internet seems to work fine.



回答15:

Just recreating the emulator with another target API worked for me



回答16:

I've faced the very and suddenly same problem on my MAC. After having tried everything, I've finally deleted the folder /Users/Philippe/.android and create a new emulator.



回答17:

Reminder: the Android Emulator internet connection does not work if you turn on a VPN system on you computer.



回答18:

I am on android studio 3.1 and it happened. Solved it by restarting the adb server

$ adb kill-server
$ adb start-server

Hope it helps. Thank you



回答19:

I was having the same issue and i resolved with below steps:-

Go to emulator setting and then go to

setting->Proxy->Either configure it Manually or use Tick use Android Studio HTTP proxy simulator.



回答20:

I had this also and I solved it by creating new android emulator virtual device and chosen Nexus 4 api 27. Before I was creating Pixel device api 28, and it was not working even after recreating device. So I tried totally different configuration and Android Emulator has internet connection as is expected. Other solutions did not work for me but I did no try it all.



回答21:

Finally, I had to delete the .android folder and create new one. It seems that the files got corrupted



回答22:

Maybe you set a proxy for Android Studio and the proxy does not work. Try without proxy.



回答23:

Had the same issue with my emulator,did everything above but nothing worked. Changing the Default gateway in my Control Panel -> Network and Sharing Center -> Local area connection settings from: 192.168.1.119 to 192.168.1.1 worked from me. I don't have much idea about how this IP Address works,but maybe it will save someone's time and frustation.



回答24:

For me the problem was my computer was connected to VPN. Once I disconnected that it started working in emulator.



回答25:

Pro tips: using AVD with dnsmasq on Linux

To understand you to read Set up Android Emulator networking from Android Studio.

The loopback of the emulated device is 127.0.0.1 and the host loopback can be accessed from the emulated device from 10.0.2.2.

At startup, the emulated device set its DNS nameserver by picking those from the host in /etc/resolv.conf.

But the point is, if you are using dnsmasq, you setnameserver 127.0.0.1in/etc/resolv.conf` so the emulated device will hit it's own loopback where nothing is running instead of the host loopback where there is a DNS server running.

To solve that, add -dns-server when running AVD from the CLI.

For example:

  • Cloudflare DNS: ~/Android/Sdk/emulator/emulator -avd Nexus_9_API_23 -dns-server 1.1.1.1
  • Host's dnsmasq: ~/Android/Sdk/emulator/emulator -avd Nexus_9_API_23 -dns-server 1.0.2.2


回答26:

I got a simple and permanent solution for this issue in windows.

Go to network and internet option->

click on Etherenet or wifi(for which you are connected) option ->

Click on change adapter option ->

Right click on the network for which you have connected.

A dialog box will be opened and just click on Internet protocal version (TCP/IPv4) option.

Another dialog box will be opened and there just neglect the first set about the IP address (Keep as it is set) and click radio button of Use the following DNS server addresses: and enter as 8.8.8.8 in Preferred DNS server: and 8.8.4.4 in Alternate DNS server:

Now you can open your emulator whenever and you will get internet in the android emulators.



回答27:

go to your adapter setting and change the dns to 8.8.8.8 which is google's and it will work,it worked for me



回答28:

I solved this after 8 or 9 days. Just uninstall android emulator SDK(from SDK manager) and then reinstall android emulator SDK. in 8 or 9 days i tried :

1.new windows setup
2.uninstall and install android studio
3.change windows sharing setting
4.change DNS server addresses
5.delete and create some AVDs
6.delete .android folder and create new one etc.