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.
Go to your Android\Sdk\emulator folder and open command prompt. Type emulator -list-avds to see available emulator names. Type emulator -avd name-of-your-device -netdelay none -netspeed full -dns-server 8.8. 8.8 command and press enter.
If your emulator must access the internet through a proxy server, you can configure a custom HTTP proxy from the emulator's Extended controls screen. With the emulator open, click More , and then click Settings and Proxy. From here, you can define your own HTTP proxy settings.
Bluestacks is one of the most popular Android emulators for Windows and is probably the best Android emulator for macOS as well. This emulator is built primarily for mobile gamers and claims to provide a “PC-like” gaming experience for your mobile apps.
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.
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
emulator
to emulator_original
emulator
that contains: #!/bin/bash /Users/[MY_USER_ACCOUNT]/Library/Android/sdk/emulator/emulator_original -dns-server 8.8.8.8 $@
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
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With