Internet stopped working on Android Emulator (Mac OS)

Android Emulator

Android Emulator Problem Overview


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.

enter image description here

Android Emulator Solutions


Solution 1 - Android Emulator

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

Solution 2 - Android Emulator

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.

Solution 3 - Android Emulator

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

Solution 4 - Android Emulator

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.

Solution 5 - Android Emulator

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

Solution 6 - Android Emulator

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.

Solution 7 - Android Emulator

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.

Solution 8 - Android Emulator

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.

Solution 9 - Android Emulator

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

Solution 10 - Android Emulator

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

Solution 11 - Android Emulator

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"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmitView Question on Stackoverflow
Solution 1 - Android EmulatorikaioiView Answer on Stackoverflow
Solution 2 - Android EmulatorJezView Answer on Stackoverflow
Solution 3 - Android EmulatorknarfView Answer on Stackoverflow
Solution 4 - Android EmulatorSangeetha SakthivelView Answer on Stackoverflow
Solution 5 - Android EmulatorsaschpeView Answer on Stackoverflow
Solution 6 - Android EmulatorJarvis ZhengView Answer on Stackoverflow
Solution 7 - Android EmulatorAmitView Answer on Stackoverflow
Solution 8 - Android EmulatorHerrison NascimentoView Answer on Stackoverflow
Solution 9 - Android EmulatorRaghuDView Answer on Stackoverflow
Solution 10 - Android EmulatorAnderson BressaneView Answer on Stackoverflow
Solution 11 - Android EmulatorkingsleyView Answer on Stackoverflow