Android Studio - Android Emulator Wifi Connected with No Internet

Solution 1:

Stated below are the solutions for Windows and Mac, but similar solutions will work on any OS:

  1. On Windows

    • Open Network and Sharing Center and click on current Connection
    • Click on Properties
    • Double Click on Internet Protocol Version 4 (TCP/IPv4)
    • Set the Preferred and Alternate DNS servers as (Screenshot below) :

      8.8.8.8
      8.8.4.4
      
  2. On Mac

    • Go to Settings > Network > Advanced... > DNS
    • Delete whatever entries you have there and add these two entries (Screenshot below):

      8.8.8.8
      8.8.4.4
      

      Note: For Mac users, if the entries field is disabled and you're not able to edit it, click on the 'Lock' icon in the bottom area of that window and enter the password to be able to make changes

Restart the emulator, and it should solve:

Screenshots:

  1. Windows

Android emulator not connecting to internet solution on windows

  1. Mac

Android emulator not connecting to internet solution on a mac


Edit: This is the fix for a situation when the emulator's wifi has changed the DNS to some non-working DNS. While this works most of the time, there might also be other reasons which may not fix from this solution.

Solution 2:

My solution using Mac OSX 10.13

I read about it being caused by LAN card and WiFi being enabled, and some approaches seemed complicated to me, so I simply tried this, and it worked:

  • Disabled WiFi on my laptop.
  • Switched off the emulator.
  • Did a cold boot on the emulator (AVD Manager -> on emulator actions -> Cold Boot Now).
  • After reboot with laptop WiFi disabled the emulator showed proper WiFi connection (emulator still shows AndroidWifi but is connected to my laptop internet. WiFi symbol now look like this: WiFi symbol connected)
  • I then enabled WiFi on my laptop and everything worked.

Solution 3:

It seems the previous answers to this problem no longer work in 2021 (Using Android Studio 4.1.2). The problem is the DNS settings on the Emulator. It no longer works to just change the DNS Servers on your local PC. You have to change the DNS settings within the Emulator. The following steps are for an emulator running Android 11. Other versions will be similar:

  1. Open the Extended controls dialog that opens up to the right of the emulator. Click on Settings on the dialog menu. Click on Proxy at the top and make sure Use Android Studio Http proxy settings IS CHECKED. I emphasis this because many of the previous solutions said to uncheck this. However, on the latest versions, it works better to keep this checked. If it wasn't already checked, restart the emulator before proceeding Step 2
  2. Navigate to the WiFi connection settings within the emulator: Home Screen -> Swipe up -> Settings -> Network & Internet -> WiFi AndroidWifi -> click gear icon -> click Advanced dropdown near bottom of screen -> Swipe up to view to view Network Details.
  3. What does it say for DNS. If it is NOT 8.8.8.8, follow this to fix. Write down (or remember) the IP address and Gateway address displayed there in the network settings. We need those IP addresses to fill in as static.
  4. Click the pencil icon on the top to edit the Network details. Click the IP settings dropdown and change it to Static. Then enter the IP address and Gateway that you wrote down in step 2. Make sure DNS 1 is 8.8.8.8 and DNS 2 is 8.8.4.4. These filled in automatically for me.
  5. Close the emulator and restart it using the Cold Boot Now option.

This fixed it for me after I unsuccessfully tried all the other solutions found on this page and many others. I hope it works for you.

Solution 4:

@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

Solution 5:

On macOS:

  1. Open Network in System Preferences.
  2. Select your current network from left side then click Advanced....
  3. Change Configure IPv6(under TCP/IP tab) from Automatically to Link-local only.
  4. Restart your emulator.