因特网停止了 Android 模拟器(MacOS)的工作

我正在使用 Android Studio 2.3(最新版本)。直到昨天一切都很好,工作,今天仿真器没有连接到数据网络。
到目前为止,我找不到任何有效的解决办法。我的 Mac 在 Mac OS Sierra 上运行,没有代理连接到 WiFi。

enter image description here

61131 次浏览

Couldn't find any solution by tweaking network settings. So added a new virtual device from Tools -> Android ->AVD Manager by downloading a new system image(Android O, API 26). And it's working now.

If you want to use the same API level then make sure to delete the existing system image and download it again.

In Mac OS go to: System Preferences -> Network -> select Wi-Fi os left panel -> Advanced on right panel -> DNS -> add new DNS server; for example 8.8.8.8 and 8.8.4.4 (Google Public DNS) or 1.1.1.1 and 1.0.0.1 (Cloudflare and APNIC DNS) or another public DNS provider. Then restart the emulator so the changes take effect.

DNS setup

Edited jun/2020

Another option is to pass dns-server params when start Android emulator. According with this solution https://stackoverflow.com/a/51858653/3328566, I changed the emulator executable name and I created a bash script to load the AVD with param -dns-server 8.8.8.8.

In your Android SDK default folder /Users/[MY_USER_ACCOUNT]/Library/Android/sdk/emulator/emulator

  1. Rename the binary emulator to emulator_original
  2. Create a bash script named emulator that contains:

#!/bin/bash /Users/[MY_USER_ACCOUNT]/Library/Android/sdk/emulator/emulator_original -dns-server 8.8.8.8 $@

  1. Change the script permissions with chmod +x emulator

Now, you can start AVD from Android Studio normally

In this case, you don't need to set DNS server in System Preferences. You are setting the DNS server only for the emulator, avoiding other problems

There was an update available to my Android Studio, i updated it and it worked!

For me the issue appears to stem from the DNS settings my company enforces.

In order to be able to get network access for my emulator I needed to launch the emulator with the same corporate dns-server specified.

I'm on a Mac, so first I checked my network settings to find what my DNS was set to:

System Preferences -> Network -> Wi-Fi -> Advanced -> DNS

Then navigated to the sdk emulator location (for convenience):

cd ~/Library/Android/sdk/emulator

Then listed the available emulators:

./emulator -list-avds

Then ran the desired emulator with dns server override:

./emulator @<emulator_name> -dns-server <dns.server.ip.address>

It would be nice if I could set this DNS to be used by emulators launched through Android Studio, but hopefully these steps help someone else in a similar position.

If you have Blue Coat Unified Agent, internet wont work. Kindly uninstall it.

It can be uninstalled by going to below folder- /Library/Application Support/bcua

if its an android project, u can change the baseUrl to 10.0.2.2, note this is only applicable from android emulator, will not work on phone

e.g Api endpoint will now look like this: val baseUri : String = "http://10.0.2.2/restapi/"

val loginEndpoint = "${baseUri}login"

I'm new to Android Studio and just ran into this issue. Network in the sim was working fine and stopped working for some reason. Didn't like any of the solutions above, so I poked around the AVD Manager and found an option to wipe the data on the sim.

  1. quit the sim
  2. open AVD Manager
  3. Actions > open down arrow for more options
  4. select Wipe Data
  5. restart sim

Wipe simulator data in AVD Manager

Go to open AVD manager and click wipe data

Click on the wipe data

That's it now the Internet will work. This is how I solved my Issue.

It's a bug with IPv6 name resolution, removing any IPv6 nameserver in /etc/resolv.confg fixes the issue, see https://issuetracker.google.com/issues/155686508#comment3

You can go to: System Preferences -> Network -> Wi-Fi -> Advanced -> DNS

So you add a new DNS 8.8.8.8. It might solve your problem.

i tried purge all android studio files and reinstall, start with -dns-server, wifi dns to 8.8.8.8, none of them not working for me. i found it only can using ip address in emulator. but this post saved me. https://www.bswen.com/2021/08/others-how-to-enable-android-emulator-internet-access.html.
1\ turn off you macos wifi; 2\ cold boot emulator; 3\ waiting the emulator's wifi connected (limited connection but it's ok) 4\ turn on you macos wifi; it's working now.

None of the answers worked for me on a m1 mac, I was not even able to connect to localhost for the react-native development server.

The trick for me was to turn off the cellular data "T-mobile," then it would use AndroidWiFi for internet and everything worked fine.

Here's a screenshot of my working settings: enter image description here