Android Studio - Android Emulator Wifi Connected with No Internet

前端 未结 21 1556
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 13:42

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

相关标签:
21条回答
  • 2020-11-27 14:12

    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.
    0 讨论(0)
  • 2020-11-27 14:12

    On Mac OSX (Catalina for me), the problem is caused by the fact that the emulator automatically picks up the nameserver by looking at /etc/resolv.conf and picking the first one, in my case an IPv6 address. Source: https://developer.android.com/studio/run/emulator-networking#dns

    Simply edit the file (sudo vi /etc/resolv.conf) and move the IPv4 address (192.168.1.1 in my case) to be first, before the IPv6 addresses. Seriously, that was it.

    0 讨论(0)
  • 2020-11-27 14:17

    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

    1. 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.

    0 讨论(0)
  • 2020-11-27 14:18

    @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

    0 讨论(0)
  • 2020-11-27 14:18

    If the wifi spot has changed, simple restart the emulator so the emulator refresh network settings from dhcp service.

    0 讨论(0)
  • 2020-11-27 14:18

    For new searcher users: Sometimes VPN is your solution Changing of network setting is not possible always because of networking issues. If you are in ip addresses that google does not responding for these regions,your solution is using of vpn.Use a proper vpn (a vpn that trough it you could update your android studio).When your vpn is on start your avd device (ofcourse api level of your emulator is important for example I have not any problem with api 22 but for api 28 is need using of vpn !).This was my experience about android emulator internet.

    0 讨论(0)
提交回复
热议问题