This happens from time to time on the Android emulator that lives on my computer — I launch an instance to work on and it just decides that it doesn’t want to connect to the internet. This is usually followed by the typical turn off and on the WiFi on the emulator, then on the computer and then either wipe all the data and relaunch or just creating a new instance to see if it would magically work.
The problem here seems to be related to the DNS picked by the Android emulator, which it cannot resolve and therefore connect to the internet.
Since the problem is related to the DNS used by the emulator (by default, it uses the same as your machine) the approach that I’ve taken is just to launch the emulator configured to connect to Google’s public DNS’ — 126.96.36.199.
emulator @<your_emulator_name> -dns-server 188.8.131.52
How to find your emulator name?
You can see all the emulators that you’ve created by entering the following command on the terminal/shell:
How to use the emulator command?
Depending on the operating system that you’re using the emulator is under:
- On Mac
- On Windows
You can find these locations by using:
- On Android Studio by right + click on your project
- “Open Module Settings”
- Look on the sidebar for “SDK Location” and select this tab
- You should now have a couple of directories there, namely “Android SDK location” which is the one that we’re looking for
Now, let’s add it to your environment path:
- On Mac:
$ cd ~
$ open .bash_profile
And add the Android SDK locations copied from Android Studio:
Close and execute the commands just added
$ source .bash_profile
Just to test that everything is working as expected try to enter this command:
$ adb version
- On Windows
You’ll need to add the
ANDROID_HOME to the “System variables”. You’ll need to:
- Go to System → Advanced system settings
- Select the “Advanced” tab
- Click on “Environment Variables…”
- And under “System variables” add