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.
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
Rename the binary emulator to emulator_original
Create a bash script named emulator that contains:
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.
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.
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.