Why?
Sometimes, the Android emulator does not connect to internet, this might happen if there is a custom DNS server on the network.
This has become a classical emulator issue, but there is no simple way to quickly fix it other than using the emulator’s UI to set static local IP address along with a new DNS inside the network settings.
How?
A quick fix is to run the emulator with a custom DNS using command line. This might not be the best long-term fix, but it might come handy in some situations.
# Get a list of android emulators on your device
emulator -list-avds
# Run an emulator with DNS set to 8.8.8.8 (Google)
emulator -avd Pixel_2_API_30 -dns-server 8.8.8.8
This will open the emulator with DNS already set to “8.8.8.8”.