Android Studio-未连接互联网的Android模拟器Wifi [英] Android Studio - Android Emulator Wifi Connected with No Internet

查看:546
本文介绍了Android Studio-未连接互联网的Android模拟器Wifi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浪费了一整天的时间来尝试在SO和提到的其他地方浮动的不同解决方案,以在android模拟器上启用wifi,但无济于事. 有人可以帮我弄清楚如何在我的android模拟器上启用互联网吗?

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?

我有Nexus 5X API 27,目标是Android 8.1(Google Play) Nexus 5 API P,目标是Android 7.1.1.

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.

我相信应该有一种方法可以在其上启用Internet,否则在模拟器上提供虚拟wifi的整个点似乎是浪费的.

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.

我在Mac OS HS 10.13.4上直接连接到路由器,没有代理.

I am on mac OS HS 10.13.4 directly connected to my router with no proxy.

我什至尝试删除所有AVD,然后重新安装它们.我什至尝试在Oreo Android 8.1上安装最新的Pixel 2

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

谢谢, 维克拉姆

更新:当我通过手机将计算机连接为热点wifi时,模拟器可以通过wifi上网,但是当我将计算机连接到家庭路由器时,仿真器将失败.

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:我发现并解决了这个问题.问题是当您通过路由器连接时,模拟器中的androidwifi使用设置并将DNS设置为8.8.8.8以外的其他值,这是google DNS(我想这是androidwifi获取互联网的一种强制性设置使用权).但是,如果我在网络设置中更改了DNS,则将不会下载获取您的依赖项(尤其是从jcenter()下载的依赖项)的google-services插件,因此您的同步将会失败,最终将使您的构建失败.

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

因此,诀窍在于,在默认路由器设置之后,您已在网络设置中配置了Google DNS(8.8.8.8)-该部分负责从jcenter()下载依赖项,并且同步和构建成功.

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.

现在从终端使用emulator @Nexus_5X_API_27 -dns-server 8.8.8.8命令启动仿真器,这将强制仿真器使用8.8.8.8作为其DNS,并且仿真器将具有Internet.

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.

我正在开发一个本机应用程序,因此对我来说android studio是不必要的,并且我已将bashrc配置为如下启动不同的模拟器,

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
   }

因此,我从一个终端启动了我选择的模拟器,然后在另一个终端上运行了构建,该终端在启动的模拟器上运行了我的应用程序,并且我的FREAKING EMULATOR具有Internet访问权限. :)

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.

谢谢, 维克拉姆

这篇关于Android Studio-未连接互联网的Android模拟器Wifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆