An Emulator Networking Workaround

I use the Android SDK emulator a lot less than do many developers. I have a fair bit of hardware and prefer to test on it, since users do not use emulators. I usually only crack open an emulator for showing demos in training, conference presentations, and the like.

So, somewhere in the past few months, my emulators lost the ability to access the Internet. The “wireless signal” status bar icon showed four bars with the little “x” indicating no Internet access. The problem persisted across actual networks, indicating that the problem was not tied to WiFi, VPNs, or anything variable about my development machine.

After a lot of searching, this answer has more or less addressed my problem. I say “more or less” in that I cannot use the AVD Manager or Android Studio to start the emulator, but instead need to start it from the command line.

For whatever reason, the emulator has some difficult obtaining the DNS server from DHCP (or whatever facsimile of DHCP gets used by the emulator for its networking). Instead, I need to manually stipulate the DNS server via the -dns-server command-line option. So, I wind up running the emulator from the command line like this:

$ANDROID_SDK/emulator/emulator -avd ... -dns-server 8.8.8.8

(where $ANDROID_SDK is where the Android SDK is installed and ... is the AVD name as found in the ~/.android/avd directory)

Then, the emulator behaves normally from a networking standpoint.