I have wasted a whole day trying out different solutions floating around in SO and other place mentioned to enable wifi on the android emulator but to no avail. Can anybody help me figure out how do I enable internet on my android emulator?
I have Nexus 5X API 27 and target being Android 8.1 (Google Play) and Nexus 5 API P and target being Android 7.1.1.
I believe there should be a way to enable internet on it or else the whole point of providing virtual wifi on the emulator seems to be waste.
I am on mac OS HS 10.13.4 directly connected to my router with no proxy.
I even tried deleting all the AVDs, re-installing them. I even tried having installed the latest Pixel 2 with Oreo Android 8.1
Nothing seems to be working. Has anybody faced this issue and found a solution?
Any help would be of great help
Thanks, Vikram
Update: When I connect my computer through my phone as hotspot wifi, the emulator has internet through wifi, but it fails when I connect my computer to my home router.
@TheBaj : I figured the problem with this and fixed it. The problem is when you are connected through the router, the androidwifi in your emulator uses the settings and the sets the DNS to something other than 8.8.8.8 which is the google DNS(I presume this is kinda mandatory setting for the androidwifi to gain internet access). But if i change the DNS in my network settings, the google-services plugin which fetches your dependencies especially the one's getting downloaded from jcenter()
will not be downloaded and hence your sync will fail which eventually fails your build.
So the trick is that you have your google DNS(8.8.8.8) configured in your network settings after your default router settings - this part takes care of downloading the dependencies from jcenter()
and the sync and build succeeds.
Now launch your emulator with emulator @Nexus_5X_API_27 -dns-server 8.8.8.8
command from the terminal which forces the emulator to use 8.8.8.8 as its DNS and the emulator will have internet.
I am working on a react-native app, so for me android studio is needless and i have configured my bashrc to launch the different emulators as follows,
function emunex5 {
emulator @Nexus_5X_API_27 -dns-server 8.8.8.8
}
function emunex6 {
emulator @Nexus_6_API_27 -dns-server 8.8.8.8
}
function emupix {
emulator @Pixel_XL_API_27 -dns-server 8.8.8.8
}
So from one terminal i launch the emulator of my choice and then run the build on another terminal which runs my app on the launched emulator and MY FREAKING EMULATOR HAS INTERNET ACCESS. :)
Try this out and i hope this helps.
Thanks, Vikram