Internet stopped working on Android Emulator (Mac

2020-02-07 19:40发布

问题:

I am using Android Studio 2.3(Latest). Till yesterday it was all good and working, today emulator is not connecting to the data network.
I couldn't find any solution working so far. My Mac is running on Mac OS Sierra, connected to WiFi with no proxy.

回答1:

In Mac OS go to: System Preferences -> Network -> select Wi-Fi os left panel -> Advanced on right panel -> DNS -> add new DNS server "8.8.8.8"

It solves for me



回答2:

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.



回答3:

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.



回答4:

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



回答5:

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



回答6:

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"