简体   繁体   English

Android 模拟器无法访问 inte.net

[英]Android emulator not able to access the internet

I know that similar questions have been asked before, but my problem is new only after installing Android Studio 2.3, the latest version in March 2017. I have several years experience developing Android applications, and I have never encountered this problem before.我知道以前有人问过类似的问题,但我的问题是安装 Android Studio 2.3 后才出现的,最新版本是 2017 年 3 月。我有几年开发 Android 应用程序的经验,以前从未遇到过这个问题。 After upgrading to version 2.3 of Android Studio, my emulator is no longer able to access the inte.net.升级到Android Studio 2.3版本后,我的模拟器不能上网了。 I even uninstalled/reinstalled Android Studio 2.3 from scratch and created a new emulator, and I am still getting the same error.我什至从头开始卸载/重新安装 Android Studio 2.3 并创建了一个新的模拟器,但我仍然遇到同样的错误。 This is not an app problem.这不是应用程序问题。 I can't even access the inte.net from Chrome, and I wasn't having this problem last week.我什至无法从 Chrome 访问 inte.net,上周我没有遇到这个问题。 The message that I get says that the server DNS address could not be found -- DNS_PROBE_FINISHED_BAD_CONFIG.我收到的消息说找不到服务器 DNS 地址 -- DNS_PROBE_FINISHED_BAD_CONFIG。 The only thing that has changed on my computer in the last week is the new version of Android plus possibly updates to Windows 10. And yes, my computer has access to the inte.net.上周我的电脑上唯一发生变化的是新版本 Android 以及可能更新到 Windows 10。是的,我的电脑可以访问 inte.net。 Below is an image of my emulator when I try to use Chrome to search for "Google".下面是当我尝试使用 Chrome 搜索“Google”时我的模拟器的图像。 带有错误消息的模拟器

👉 1st try "Cold booting" the emulator as suggested here . 👉 第一次尝试按照此处的建议“冷启动”模拟器。

👉 If cold booting doesn't work, try changing the DNS address of your network to 8.8.8.8 (Google's DNS) or another of your preference: 👉 如果冷启动不起作用,请尝试将网络的 DNS 地址更改为 8.8.8.8(Google 的 DNS)或您喜欢的其他地址:

MacOSX: macOS:

  • Open "System Preferences"打开“系统偏好设置”
  • Click on "Network"点击“网络”
  • Select the network which your computer is connected and click on "Advanced"选择您的计算机连接的网络,然后单击“高级”
  • Select "DNS", Select the "+" button, type "8.8.8.8" (Google's DNS) or if you prefer OpenDNS, "208.67.222.222"选择“DNS”,选择“+”按钮,输入“8.8.8.8”(Google 的 DNS),或者如果您更喜欢 OpenDNS,请输入“208.67.222.222”
  • Select "Ok" and "Apply"选择“确定”和“应用”

Windows & Linux:视窗和 Linux:

https://developers.google.com/speed/public-dns/docs/using https://developers.google.com/speed/public-dns/docs/using


After that close the emulator and start it again.之后关闭模拟器并重新启动它。

After trying many of these solutions, I was going to just delete my current AVD and make it again, but when I clicked the down arrow on the AVD, I noticed "Cold Boot Now".在尝试了许多这些解决方案之后,我打算删除我当前的 AVD 并重新创建它,但是当我单击 AVD 上的向下箭头时,我注意到“现在冷启动”。

AVD 菜单

On a whim I tried that.一时兴起,我试过了。 Lo and behold my emulator has internet connectivity again!瞧,我的模拟器又可以上网了!

Command-line approach命令行方法

In case you start Emulator through command, pass -no-snapshot-load option, like:如果您通过命令启动 Emulator,请传递-no-snapshot-load选项,例如:

%ANDROID_HOME%/emulator/emulator.exe -netdelay none -netspeed full -no-snapshot-load -avd Pixel_2_API_28

Or for MacOSX:或者对于 MacOSX:

$ANDROID_HOME/emulator/emulator -netdelay none -netspeed full -no-snapshot-load -avd Pixel_2_API_28

Note that you may need to change -avd Pixel_2_API_28 part (with your own Virtual-Device name).请注意,您可能需要更改-avd Pixel_2_API_28部分(使用您自己的虚拟设备名称)。

Also, most tools use ANDROID_HOME environment-variable name, hence define that (if not already), but nowadays ANDROID_ROOT is yet another naming-option.此外,大多数工具使用ANDROID_HOME环境变量名称,因此定义(如果尚未),但现在ANDROID_ROOT是另一个命名选项。

Decision (edit)决定(编辑)

Ok, for those saying why not just wipe data and restart.好的,对于那些说为什么不只是擦除数据并重新启动的人。 Do you reformat your PC every time you restart it?每次重新启动电脑时都会重新格式化电脑吗? Wiping data on the emulator is just like doing a factory reset to a phone or reformatting your hard drive on your PC and reinstalling your OS.在模拟器上擦除数据就像对手机进行出厂重置或在 PC 上重新格式化硬盘并重新安装操作系统一样。 It is unnecessary unless the data is totally corrupt.除非数据完全损坏,否则这是不必要的。

When you shut off the emulator and restart it, it is like putting your PC in hibernate or sleep mode.当您关闭模拟器并重新启动它时,就像将您的 PC 置于休眠或睡眠模式一样。 Memory is not wiped, it is saved.内存没有被擦除,它被保存了。

Doing a cold boot is the same as rebooting your phone or rebooting your PC.冷启动与重新启动手机或重新启动 PC 相同。 It resets memory and lets things reload.它重置内存并让事情重新加载。 This allows the network emulation to start with clean memory and connect properly.这允许网络仿真从干净的内存开始并正确连接。

So, don't wipe your data.所以,不要擦除你的数据。 Just cold boot.只是冷启动。 If it still doesn't work, then wipe, but save that as a last resort.如果它仍然不起作用,请擦拭,但将其保存为最后的手段。

I found a temporary solution on an old Stack Overflow thread at Upgraded to SDK 2.3 - now no emulators have connectivity .我在Upgraded to SDK 2.3 的旧 Stack Overflow 线程上找到了一个临时解决方案 - 现在没有仿真器具有连接性 Note that this thread talks about Android SDK 2.3, not Android Studio 2.3.请注意,此线程讨论的是 Android SDK 2.3,而不是 Android Studio 2.3。 The problem seems to be that the emulator can't find the DNS my computer is currently using, and the temporary workaround is to start the emulator from the command line and specify the DNS server.问题似乎是模拟器找不到我的电脑当前使用的DNS,临时的解决方法是从命令行启动模拟器并指定DNS服务器。 Whatever problem occurred back then must have reappeared in the latest version of Android Studio.那时发生的任何问题都必须在最新版本的 Android Studio 中重新出现。

The temporary solution outlined below fixes the problem with the emulator accessing the internet.下面概述的临时解决方案解决了模拟器访问互联网的问题。 However, it does not fix the problem that occurs when trying to run Android Device Monitor.但是,它不能解决尝试运行 Android Device Monitor 时出现的问题。 Doing so will still make the emulator go offline as described above.这样做仍然会使模拟器如上所述脱机。

Note that there are two files named "emulator.exe" in the sdk -- one under sdk\tools and another under sdk\emulator.请注意,sdk 中有两个名为“emulator.exe”的文件——一个在 sdk\tools 下,另一个在 sdk\emulator 下。 Either might work below, but I use the one under sdk\emulator.两者都可能在下面工作,但我使用 sdk\emulator 下的那个。

The first step is to find where the SDK is located.第一步是找到SDK所在的位置。 Assuming a user name of "jdoe" and a default installation of Android Studio on Windows, the SDK is most likely in假设用户名为“jdoe”并且在 Windows 上默认安装了 Android Studio,那么 SDK 最有可能在

C:\Users\jdoe\AppData\Local\Android\sdk

The second step is to determine the name of the AVD (emulator) that you want to run.第二步是确定要运行的 AVD(模拟器)的名称。 The command命令

C:\Users\jdoe\AppData\Local\Android\sdk\emulator\emulator.exe -list-avds

will show the names of your AVDs.将显示您的 AVD 的名称。 On my computer, it shows only one, Nexus_5X_API_25.在我的电脑上,它只显示一个,Nexus_5X_API_25。

To start the emulator from the command line with a specified DNS server, use something like the following:要使用指定的 DNS 服务器从命令行启动模拟器,请使用类似以下内容:

C:\Users\jdoe\AppData\Local\Android\sdk\emulator\emulator.exe -avd Nexus_5X_API_25 -dns-server 8.8.8.8

In this case, 8.8.8.8 is a Google public domain name server.在这种情况下, 8.8.8.8是一个谷歌公共域名服务器。

The above commands can be shortened if you create appropriate environment variables and edit your PATH environment variable, but I recommend caution when doing so.如果您创建适当的环境变量并编辑您的 PATH 环境变量,上述命令可以缩短,但我建议这样做时要小心。

[UPDATE 2022] for Mac Users [更新 2022]适用于 Mac 用户

For NOT Apple Silicon users对于非Apple Silicon用户

  1. System Preferences系统偏好
  2. Network网络
  3. WiFi > Select Advanced WiFi > 选择高级
  4. From Advanced Choose DNS tab从高级选择 DNS 选项卡
  5. Add DNS Server 8.8.8.8添加 DNS 服务器 8.8.8.8
  6. Emulator must be restarted after DNS Server has been added (Thanks to @kapusch)添加 DNS 服务器后必须重新启动模拟器(感谢@kapusch)

For Apple Silicon users对于Apple Silicon用户

as per @bourdier-jonathan You can fix the Silicon issue here: Emulator appearing offline on M1 Mac after the last update of arm64-v8a根据@bourdier-jonathan 您可以在此处修复硅问题: Emulator 在最后一次更新 a​​rm64-v8a 后在 M1 Mac 上脱机

By replacing the AVD system images you have downloaded with the r02 images.通过将您下载的 AVD 系统映像替换为 r02 映像。 Because It appears r03, r04, and r05 all don't work on m1因为看起来 r03、r04 和 r05 都不适用于 m1

Updating my WIFI adapter to resolve DNS on 8.8.8.8 solved the issue for me.更新我的 WIFI 适配器以解析 8.8.8.8 上的 DNS 为我解决了这个问题。 It started to happen after an Apple update which messed up the DNS address.它开始发生在 Apple 更新弄乱了 DNS 地址之后。

在此处输入图像描述

只需打开AVD 管理器并擦除该模拟器的数据即可。

Open Android emulator and go to the Extended Controls .打开 Android 模拟器并转到Extended Controls Then go to the setting => proxy(Tab), uncheck "Use Android studio HTTP proxy setting" and click "Apply".然后转到设置=>代理(Tab),取消选中“使用Android Studio HTTP代理设置”并单击“应用”。

macOS: long Story short.. make sure your DNS settings 8.8.8.8 is the first in line, wipe your data and do a cold boot. macOS:长话短说..确保您的 DNS 设置8.8.8.8是第一个,擦除您的数据并进行冷启动。

在此处输入图像描述

I experienced this same issue after upgrade.升级后我遇到了同样的问题。 Upon opening the Chrome browser in the emulator, google.com could no longer be reached.在模拟器中打开 Chrome 浏览器后,无法再访问 google.com。

I found a post on SO that suggested the problem was with the emulator trying to use a disconnected network adapter.在 SO 上发现了一个帖子,表明问题出在模拟器试图使用断开连接的网络适配器。 For me the problem was occurring when I was connected to a LAN.对我来说,当我连接到 LAN 时,问题就出现了。 Disabling the wireless LAN adapter fixed the issue.禁用无线 LAN 适配器解决了该问题。

To disable the adapter:要禁用适配器:

  1. Navigate to Network connections导航到网络连接
  2. Find the adapter找到适配器
  3. Right click and choose disable右键单击并选择禁用

我已经解决了从 AVD Manager 中擦除数据的问题

提醒:如果您在计算机上打开VPN系统,Android Emulator 互联网连接将无法正常工作

This happend to me when the emulator froze and I had to kill the process.当模拟器冻结并且我不得不终止该进程时,这发生在我身上。 The signal icon always showed the small "x" as in the screenshot and no internet connection was successful.信号图标始终显示小“x”,如屏幕截图所示,并且没有成功连接互联网。

The only thing that helped was uninstalling and reinstalling the emulator (not the AVD images)唯一有帮助的是卸载并重新安装模拟器(不是 AVD 图像)

In Android Studio:在 Android Studio 中:

Tools-> Android -> SDK Manager Uncheck "Android Emulator" and let it uninstall then check again and let it install again. Tools-> Android -> SDK Manager 取消选中“Android Emulator”并让它卸载然后再次检查并再次安装。

截屏

I am also facing the same problem, but I am trying to solve the problem using various posts.我也面临同样的问题,但我正在尝试使用各种帖子来解决问题。 Today I discovered this problem.今天我发现了这个问题。 Your computer configuration is most likely the problemm, not Android Studio and the Android Emulator.您的计算机配置很可能是问题所在,而不是 Android Studio 和 Android 模拟器。

The problem is coming from your Network setup.问题来自您的网络设置。 Just set the Primary DNS Server to 8.8.8.8, which will solve the problem.只需将 Primary DNS Server 设置为 8.8.8.8,即可解决问题。

I got a simple and permanent solution for this issue in windows.我在 Windows 中为这个问题找到了一个简单而永久的解决方案。

Go to network and internet option->转到网络和互联网选项-> 在此处输入图像描述

click on Etherenet or wifi (for which you are connected) option ->单击以太网wifi (您已连接)选项-> 在此处输入图像描述

Click on change adapter option ->单击更改适配器选项-> 在此处输入图像描述

Right click on the network for which you have connected.右键单击您已连接的网络。 在此处输入图像描述

A dialog box will be opened and just click on Internet protocal version (TCP/IPv4) option.将打开一个对话框,只需单击Internet 协议版本 (TCP/IPv4)选项。 在此处输入图像描述

Another dialog box will be opened and there just neglect the first set about the IP address (Keep as it is set) and click radio button of Use the following DNS server addresses: and enter as 8.8.8.8 in Preferred DNS server: and 8.8.4.4 in Alternate DNS server:将打开另一个对话框,忽略关于 IP 地址的第一个设置(保持原样)并单击单选按钮使用以下 DNS 服务器地址:并在首选 DNS 服务器中输入 8.8.8.8:和 8.8。 4.4 在备用 DNS 服务器中: 在此处输入图像描述

Now you can open your emulator whenever and you will get internet in the android emulators.现在你可以随时打开你的模拟器,你会在安卓模拟器中上网。

This was a problem for me last time the emulator updated itself and back then disabling other network adapters fixed it.上次模拟器自我更新时,这对我来说是个问题,然后禁用其他网络适配器修复了它。 Now it's cropped up again but the only adapter that is enabled is a single wifi one so I have nothing to disable.现在它又出现了,但唯一启用的适配器是一个 wifi 适配器,所以我没有什么可以禁用的。

The issue only reappeared after I updated via a prompt the emulator tools to 26.1.1.只有在我通过提示将模拟器工具更新到 26.1.1 后,该问题才再次出现。 I uninstalled and reinstalled the emulator via the SDK Tools update tab and thankfully the only option when installing again right now is to install 26.0.3 (which seems to be working okay).我通过 SDK 工具更新选项卡卸载并重新安装了模拟器,幸运的是,现在再次安装时唯一的选择是安装 26.0.3(这似乎工作正常)。

Moral of the story is to be very wary of emulator updates .故事的寓意是要非常警惕模拟器的更新

For me the problem was caused when I took my laptop home without restarting the emulator.对我来说,这个问题是在我把笔记本电脑带回家而不重新启动模拟器时引起的。 From what I have read, when the emulator starts up it reads your PC's DNS settings and uses them.根据我的阅读,当模拟器启动时,它会读取您 PC 的 DNS 设置并使用它们。 When I was on my home network, my work DNS settings were failing.当我在我的家庭网络上时,我的工作 DNS 设置失败。
So yeah.是的。 Just restarting the emulator solved my problem.只需重新启动模拟器就解决了我的问题。

I faced this problem after i kept my emulator ON while going from my home to a cafe.我在从家去咖啡馆时打开模拟器后遇到了这个问题。 "Cold Boot Now" fixed the issue. “现在冷启动”解决了这个问题。

After 10 days of trouble, I just deleted everything from C:\Android\.android\ and deleted all created AVDs.经过 10 天的麻烦,我刚刚删除了C:\Android\.android\中的所有内容,并删除了所有创建的 AVD。 Now internet seems to work fine.现在互联网似乎工作正常。

closing the emulator and reopening worked for me关闭模拟器并重新打开对我有用

OS WINDOWS 10操作系统WINDOWS 10

刚刚转到 AVD 管理器和冷启动现在为我工作

I can make it work after turn off and turn on the wifi on android config我可以在关闭并打开android配置上的wifi后使其工作

打开和关闭 wifi

I am on android studio 3.1 and it happened.我在 android studio 3.1 上,它发生了。 Solved it by restarting the adb server通过重启adb服务器解决了

$ adb kill-server
$ adb start-server

Hope it helps.希望能帮助到你。 Thank you谢谢

我也遇到了问题,通过在 Android Studio 设置中禁用代理,并使用“Cold Boot Now”运行模拟器,问题得到解决。

Please go through the below link.请通过以下链接。

https://developer.android.com/studio/run/emulator-networkinghttps://developer.android.com/studio/run/emulator-networking

Emulator open, click More ... , and then click Settings and Proxy.打开模拟器,点击更多... ,然后点击设置和代理。 From here, you can define your own HTTP proxy settings.从这里,您可以定义自己的 HTTP 代理设置。


Enter the hostname by following Run > cmd > hostname通过以下Run > cmd > hostname输入主机名

Finally, check the internet access inside the emulator by browsing in chrome or google.最后,通过在 chrome 或 google 中浏览来检查模拟器内部的互联网访问。

Note: Often wipe data will clear the issue.注意:经常擦除数据会清除问题。 Please follow all steps请按照所有步骤

if android browser can access internet you can run emulator from terminal by this command如果android浏览器可以访问互联网,您可以通过此命令从终端运行模拟器

go to SDK path then然后转到SDK路径

$ /tools/emulator -avd Nexus_5X_API_23 -netdelay none -netspeed full $ /tools/emulator -avd Nexus_5X_API_23 -netdelay none -n​​etspeed full

it solve your internet problem...它解决了您的互联网问题...

I was having the same issue and i resolved with below steps:-我遇到了同样的问题,我通过以下步骤解决了:-

Go to emulator setting and then go to转到模拟器设置,然后转到

setting->Proxy->Either configure it Manually or use Tick use Android Studio HTTP proxy simulator. setting->Proxy->手动配置或者使用Tick使用Android Studio HTTP代理模拟器。

please vote, if this works for you请投票,如果这对你有用

只是用另一个目标 API 重新创建模拟器对我有用

Maybe you set a proxy for Android Studio and the proxy does not work.也许您为 Android Studio 设置了代理,但代理不起作用。 Try without proxy.尝试不使用代理。

Solution for MacOS that does not use a custom DNS for your whole machine不为整机使用自定义 DNS 的 MacOS 解决方案

Step 1步骤1

Locate the emulator executable Android Studio is using inside the Android SDK and rename it to emulator-original .在 Android SDK 中找到 Android Studio 正在使用的emulator可执行文件,并将其重命名为emulator-original

Mine is located /usr/local/share/android-sdk/emulator/emulator but it might vary based on individual setups.我的位于/usr/local/share/android-sdk/emulator/emulator但它可能因个人设置而异。

Step 2第2步

Add a new file called emulator in the place of the original file containing the following command (or using your DNS server of choice).添加一个名为emulator的新文件来代替包含以下命令的原始文件(或使用您选择的 DNS 服务器)。

#!/bin/bash
$0-original "$@" -dns-server 8.8.8.8

Step 3第 3 步

Make the new emulator file executable.使新的emulator文件可执行。

chmod +x emulator

Step 4第4步

Restart the emulator using Android Studio.使用 Android Studio 重启模拟器。

I've faced the very and suddenly same problem on my MAC.我在我的 MAC 上遇到了同样的问题。 After having tried everything, I've finally deleted the folder /Users/Philippe/.android and create a new emulator .在尝试了一切之后,我终于删除了文件夹/Users/Philippe/.android 并创建了一个新的 emulator

Pro tips: using AVD with dnsmasq on Linux专业提示:在 Linux 上使用 AVD 和 dnsmasq

To understand you to read Set up Android Emulator networking from Android Studio.要了解您,请阅读从 Android Studio设置 Android 模拟器网络

The loopback of the emulated device is 127.0.0.1 and the host loopback can be accessed from the emulated device from 10.0.2.2 .模拟设备的环回是127.0.0.1 ,主机环回可以从10.0.2.2的模拟设备访问。

At startup, the emulated device set its DNS nameserver by picking those from the host in /etc/resolv.conf .在启动时,模拟设备通过从/etc/resolv.conf中的主机中选择它们来设置其 DNS 名称服务器。

But the point is, if you are using dnsmasq , you set nameserver 127.0.0.1 in /etc/resolv.conf` so the emulated device will hit it's own loopback where nothing is running instead of the host loopback where there is a DNS server running.但关键是,如果您使用的是 dnsmasq , you set nameserver 127.0.0.1 in因此模拟设备将在没有运行任何内容的情况下命中它自己的环回,而不是运行 DNS 服务器的主机环回.

To solve that, add -dns-server when running AVD from the CLI.要解决这个问题,请在从 CLI 运行 AVD 时添加-dns-server

For example:例如:

  • Cloudflare DNS: ~/Android/Sdk/emulator/emulator -avd Nexus_9_API_23 -dns-server 1.1.1.1 Cloudflare DNS: ~/Android/Sdk/emulator/emulator -avd Nexus_9_API_23 -dns-server 1.1.1.1
  • Host's dnsmasq: ~/Android/Sdk/emulator/emulator -avd Nexus_9_API_23 -dns-server 1.0.2.2主机的 dnsmasq: ~/Android/Sdk/emulator/emulator -avd Nexus_9_API_23 -dns-server 1.0.2.2

I am having visual studio 2017 , and this simple few click has fix internet issue for Android emulator.我有visual studio 2017,这个简单的几次点击修复了Android模拟器的互联网问题。

在此处输入图像描述

  1. first:open airplane mode.第一:打开飞行模式。
  2. second:connect to emulator wifi.第二:连接模拟器wifi。

Try these steps once, they worked for me:尝试这些步骤一次,它们对我有用:

  1. Disconnect your PC from the internet断开您的 PC 与互联网的连接
  2. Close the emulator while you are still disconnected在您仍然断开连接时关闭模拟器
  3. Again connect to the internet再次连接到互联网
  4. Finally start your emulator again最后再次启动你的模拟器

As pointed by @osama buzdar, the DNS settings the emulator looks first might be specified in /etc/resolv.conf .正如@osama buzdar 所指出的, 模拟器首先查看的 DNS 设置可能在 /etc/resolv.conf 中指定 In my case, as of macOS Catalina 10.15.7, there was 2 addresses in that file: the first one was a IPv6 and the second, IPv4 and for some reason the emulator was probably having trouble with the IPv6.就我而言,从 macOS Catalina 10.15.7 开始,该文件中有 2 个地址:第一个是 IPv6,第二个是 IPv4,由于某种原因,模拟器可能在使用 IPv6 时遇到了问题。

Then I edited the file ( sudo vi /etc/resolv.conf ) and moved the IPv4 up to be the first entry of the file, before the IPv6.然后我编辑了文件( sudo vi /etc/resolv.conf )并将 IPv4 上移到文件的第一个条目,在 IPv6 之前。 Restarted the emulator and it worked.重新启动模拟器,它工作。

Apple MacBook M1苹果 MacBook M1

None of the answers worked for me on a m1 mac, I was not even able to connect to localhost for the react-native development server.在 m1 mac 上,没有一个答案对我有用,我什至无法连接到 react-native 开发服务器的本地主机。

The trick for me was to turn off the cellular data "T-mobile," then it would use AndroidWiFi for inte.net and everything worked fine.对我来说,诀窍是关闭蜂窝数据“T-mobile”,然后它将使用 AndroidWiFi 访问 inte.net,一切正常。

Here's a screenshot of my working settings:这是我的工作设置的屏幕截图: 安卓网络截图

I had this also and I solved it by creating new android emulator virtual device and chosen Nexus 4 api 27. Before I was creating Pixel device api 28, and it was not working even after recreating device.我也有这个问题,我通过创建新的 android 模拟器虚拟设备并选择了 Nexus 4 api 27 来解决它。在我创建 Pixel 设备 api 28 之前,即使在重新创建设备后它也无法工作。 So I tried totally different configuration and Android Emulator has internet connection as is expected.因此,我尝试了完全不同的配置,Android Emulator 具有预期的互联网连接。 Other solutions did not work for me but I did no try it all.其他解决方案对我不起作用,但我没有全部尝试。

For me the problem was my computer was connected to VPN.对我来说,问题是我的电脑连接到 VPN。 Once I disconnected that it started working in emulator.一旦我断开连接,它就开始在模拟器中工作。

For me on OSX, it was because of using a 3rd party VPN solution...it installs some sort of network hook that AVDs and Genymotion couldn't route through.对于 OSX 上的我来说,这是因为使用了 3rd 方 VPN 解决方案……它安装了某种 AVD 和 Genymotion 无法通过的网络挂钩。 Had to uninstall it for it work properly.必须卸载它才能正常工作。 Worked fine on some networks and not on others...was very weird..在某些网络上运行良好,而在其他网络上运行良好......非常奇怪......

I had the same problem on Windows 10. I just went to the Network & internet settings> Change adapter options> right-click on Wi-Fi and chose properties> Chose Internet protocol version 4 in the list and clicked properties> Turned on the "Use the following DNS server addresses" and filled the first part with "8.8.8.8" address .我在 Windows 10 上遇到了同样的问题。我只是去了Network & internet settings> Change adapter options> right-click on Wi-Fi and chose properties> Chose Internet protocol version 4 in the list and clicked properties> Turned on the "Use the following DNS server addresses" and filled the first part with "8.8.8.8" address Problem solved!问题解决了!

If you are behind a proxy, the following might be useful:如果您在代理后面,则以下内容可能有用:

adb shell settings put global global_http_proxy_port YOUR_PROXY_PORT

adb shell settings put global global_http_proxy_host YOUR_PROXY_IP

reboot

set DNS 8.8.4.4 and run emulator -avd react-native-device -dns-server 8.8.4.4设置 DNS 8.8.4.4 并运行 emulator -avd react-native-device -dns-server 8.8.4.4

this work for me这对我有用

The Mobile data setting requires to be turned on.移动数据设置需要打开。 Did a cold boot it didn't work but after I turned on Mobile Data it worked冷启动它没有用,但在我打开移动数据后它工作了

在具有 Jio IP6 配置问题的最新 Mac 上,它会阻止 android 模拟器上的互联网,因此从 Android 虚拟设备管理器模拟器列表操作列下拉列表中选择“立即冷启动”选项修复了问题。在我保持相同的工作后我遇到了这个问题我。

None of these answers worked for me.这些答案都不适合我。 I was able to get it working though by downloading the canary build "android-studio-2021.1.1.8-mac_arm".我可以通过下载金丝雀版本“android-studio-2021.1.1.8-mac_arm”来让它工作。 No extra steps were needed after that.之后不需要额外的步骤。

1-set no proxy 1-设置无代理

在此处输入图像描述

2-invalidate caches 2-无效缓存

在此处输入图像描述

3-remove old emulators and add new one 3-删除旧模拟器并添加新模拟器

Had the same issue with my emulator,did everything above but nothing worked.我的模拟器有同样的问题,做了上面的一切,但没有任何效果。 Changing the Default gateway in my Control Panel -> Network and Sharing Center -> Local area connection settings from: 192.168.1.119 to 192.168.1.1 worked from me.在我的控制面板 -> 网络和共享中心 -> 本地连接设置中将默认网关从:192.168.1.119 更改为 192.168.1.1 对我有用。 I don't have much idea about how this IP Address works,but maybe it will save someone's time and frustation.我不太了解这个 IP 地址是如何工作的,但也许它会节省一些人的时间和挫败感。

android emulator V 7.1.1中对我来说同样的网络连接问题,然后我在我的Android Emulator中将Android 版本降低到7.1.1以下,然后它就可以正常工作了。

Emulators w Android 9+ worked for me but Android 7 would not connect to the internet.带有 Android 9+ 的模拟器对我有用,但 Android 7 无法连接到互联网。

My office uses Little Snitch application firewall.我的办公室使用 Little Snitch 应用程序防火墙。 I turned it off and Android 7 worked.我把它关掉了,Android 7 工作了。 Probably a good idea to check your firewalls.检查防火墙可能是个好主意。

In my case it was the Charles proxy app.就我而言,它是 Charles 代理应用程序。 Even closing the app the emulator still can not access the internet.即使关闭应用程序模拟器仍然无法访问互联网。 Needed to stop listening for network in Charles.需要停止在查尔斯收听网络。

I know this is old.我知道这是旧的。 But it helped me a bit.但这对我有点帮助。 I encountered the same problem in Xamarin.Forms application.我在 Xamarin.Forms 应用程序中遇到了同样的问题。 My emulator was unable a connect to a public api.我的模拟器无法连接到公共 api。

I fixed the problem by starting the emulator with factory defaults in Android Device manager.我通过在 Android 设备管理器中使用出厂默认设置启动模拟器解决了这个问题。

在此处输入图像描述

What I have observed is that when you switch wifi connections when the android emulator is running.我观察到的是,当您在 android 模拟器运行时切换 wifi 连接时。 It isn't able to connect to new wifi.它无法连接到新的 wifi。

A simple solution is to restart the android emulator.一个简单的解决方案是重启安卓模拟器。

If you have PiHole on your network, make sure that your Pi is working and you can access the PiHole's web UI.如果您的网络上有 PiHole,请确保您的 Pi 正在工作并且您可以访问 PiHole 的 Web UI。 Every single time, when my Emulator all the sudden not getting internet connection is because something is up with either one of them.每次,当我的模拟器突然无法连接互联网时,是因为其中任何一个出现问题。

冷启动选项对我有用

Windows DNS settings are specified in the TCP/IP Properties window for the selected network connection. Windows DNS 设置在所选网络连接的 TCP/IP 属性窗口中指定。

Example: Changing DNS server settings on Windows 10示例:在 Windows 10 上更改 DNS 服务器设置

Go to the Control Panel.转到控制面板。 Click Network and Internet > Network and Sharing Center > Change adapter settings.单击网络和 Internet > 网络和共享中心 > 更改适配器设置。 Select the connection for which you want to configure Google Public DNS.选择您要为其配置 Google 公共 DNS 的连接。 For example:例如:

To change the settings for an Ethernet connection, right-click the Ethernet interface and select Properties.要更改以太网连接的设置,请右键单击以太网接口并选择属性。 To change the settings for a wireless connection, right-click the Wi-Fi interface and select Properties.要更改无线连接的设置,请右键单击 Wi-Fi 接口并选择属性。 If you are prompted for an administrator password or confirmation, type the password or provide confirmation.如果系统提示您输入管理员密码或确认,请键入密码或提供确认。

Select the Networking tab.选择网络选项卡。 Under This connection uses the following items, select Internet Protocol Version 4 (TCP/IPv4) or Internet Protocol Version 6 (TCP/IPv6) and then click Properties.在此连接使用以下项目下,选择 Internet 协议版本 4 (TCP/IPv4) 或 Internet 协议版本 6 (TCP/IPv6),然后单击属性。

Click Advanced and select the DNS tab.单击高级并选择 DNS 选项卡。 If there are any DNS server IP addresses listed there, write them down for future reference, and remove them from this window.如果那里列出了任何 DNS 服务器 IP 地址,请将它们写下来以备将来参考,然后从该窗口中删除它们。

Click OK.单击确定。

Select Use the following DNS server addresses.选择使用以下 DNS 服务器地址。 If there are any IP addresses listed in the Preferred DNS server or Alternate DNS server, write them down for future reference.如果首选 DNS 服务器或备用 DNS 服务器中列出了任何 IP 地址,请将它们写下来以备将来参考。

Replace those addresses with the IP addresses of the Google DNS servers:将这些地址替换为 Google DNS 服务器的 IP 地址:

For IPv4: 8.8.8.8 and/or 8.8.4.4.对于 IPv4:8.8.8.8 和/或 8.8.4.4。 For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.对于 IPv6:2001:4860:4860::8888 和/或 2001:4860:4860::8844。 For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.仅限 IPv6:您可以使用 Google Public DNS64 代替上一点中的 IPv6 地址。 Test that your setup is working correctly;测试您的设置是否正常工作; see Test your new settings.请参阅测试您的新设置。

Repeat the procedure for additional network connections you want to change.对要更改的其他网络连接重复此过程。

macOS DNS settings are specified in the Network window. macOS DNS 设置在“网络”窗口中指定。

Example: Changing DNS server settings on macOS 10.15示例:在 macOS 10.15 上更改 DNS 服务器设置

Click Apple menu > System Preferences > Network.单击 Apple 菜单 > 系统偏好设置 > 网络。 If the lock icon in the lower left-hand corner of the window is locked, click the icon to make changes, and when prompted to authenticate, enter your password.如果窗口左下角的锁定图标已锁定,请单击该图标进行更改,并在提示进行身份验证时输入您的密码。 Select the connection for which you want to configure Google Public DNS.选择您要为其配置 Google 公共 DNS 的连接。 For example: To change the settings for a Wi-Fi connection, select Wi-Fi, and click Advanced.例如:要更改 Wi-Fi 连接的设置,请选择 Wi-Fi,然后单击高级。 To change the settings for an Ethernet connection, select Built-In Ethernet, and click Advanced.要更改以太网连接的设置,请选择内置以太网,然后单击高级。 Select the DNS tab.选择 DNS 选项卡。 Click + to replace any listed addresses with, or add, the Google IP addresses at the top of the list: For IPv4: 8.8.8.8 and/or 8.8.4.4.单击 + 将任何列出的地址替换为或添加列表顶部的 Google IP 地址:对于 IPv4:8.8.8.8 和/或 8.8.4.4。 For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.对于 IPv6:2001:4860:4860::8888 和/或 2001:4860:4860::8844。 For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.仅限 IPv6:您可以使用 Google Public DNS64 代替上一点中的 IPv6 地址。 Click OK > Apply.单击确定 > 应用。 Test that your setup is working correctly;测试您的设置是否正常工作; see Test your new settings.请参阅测试您的新设置。 Repeat the procedure for additional network connections you want to change.对要更改的其他网络连接重复此过程。

Linux In most modern Linux distributions, DNS settings are configured through Network Manager. Linux 在大多数现代 Linux 发行版中,DNS 设置是通过网络管理器配置的。

Example: Changing DNS server settings on Ubuntu示例:在 Ubuntu 上更改 DNS 服务器设置

Click System > Preferences > Network Connections.单击系统 > 首选项 > 网络连接。 Select the connection for which you want to configure Google Public DNS.选择您要为其配置 Google 公共 DNS 的连接。 For example: To change the settings for an Ethernet connection, select the Wired tab, then select your network interface in the list.例如:要更改以太网连接的设置,请选择有线选项卡,然后在列表中选择您的网络接口。 It is usually called eth0.它通常称为 eth0。 To change the settings for a wireless connection, select the Wireless tab, then select the appropriate wireless network.要更改无线连接的设置,请选择无线选项卡,然后选择适当的无线网络。 Click Edit, and in the window that appears, select the IPv4 Settings or IPv6 Settings tab.单击编辑,然后在出现的窗口中选择 IPv4 设置或 IPv6 设置选项卡。 If the selected method is Automatic (DHCP), open the dropdown and select Automatic (DHCP) addresses only instead.如果选择的方法是自动 (DHCP),请打开下拉列表并选择仅自动 (DHCP) 地址。 If the method is set to something else, do not change it.如果方法设置为其他值,请不要更改它。 In the DNS servers field, enter the Google Public DNS IP addresses, separated by a comma: For IPv4: 8.8.8.8 and/or 8.8.4.4.在 DNS 服务器字段中,输入 Google 公共 DNS IP 地址,以逗号分隔:对于 IPv4:8.8.8.8 和/或 8.8.4.4。 For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.对于 IPv6:2001:4860:4860::8888 和/或 2001:4860:4860::8844。 For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.仅限 IPv6:您可以使用 Google Public DNS64 代替上一点中的 IPv6 地址。 Click Apply to save the change.单击应用以保存更改。 If you are prompted for a password or confirmation, type the password or provide confirmation.如果系统提示您输入密码或确认,请键入密码或提供确认。 Test that your setup is working correctly;测试您的设置是否正常工作; see Test your new settings.请参阅测试您的新设置。 Repeat the procedure for additional network connections you want to change.对要更改的其他网络连接重复此过程。 If your distribution doesn't use Network Manager, your DNS settings are specified in /etc/resolv.conf.如果您的发行版不使用网络管理器,则您的 DNS 设置在 /etc/resolv.conf 中指定。

Example: Changing DNS server settings on a Debian server Edit /etc/resolv.conf:示例:更改 Debian 服务器上的 DNS 服务器设置 编辑 /etc/resolv.conf:

sudo vi /etc/resolv.conf

If any nameserver lines appear, write down the IP addresses for future reference.如果出现任何名称服务器行,请记下 IP 地址以供将来参考。

Replace the nameserver lines with, or add, the following lines:将名称服务器行替换为或添加以下行:

For IPv4:对于 IPv4:

nameserver 8.8.8.8
nameserver 8.8.4.4

For IPv6:对于 IPv6:

nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

For IPv6-only, you can use Google Public DNS64 instead of the above IPv6 addresses.对于仅限 IPv6,您可以使用 Google Public DNS64 代替上述 IPv6 地址。

Save and exit.保存并退出。

Restart any Internet clients you are using.重新启动您正在使用的任何 Internet 客户端。

Test that your setup is working correctly;测试您的设置是否正常工作; see Test your new settings.请参阅测试您的新设置。

For Apple MacBook M1 users对于 Apple MacBook M1 用户

Working as of 1 Feb 2022截至 2022 年 2 月 1 日工作

  1. Open Android emulator打开安卓模拟器
  2. Go to Extended Controls .转到扩展控件
  3. Then go to setting under proxy ( Tab ),然后转到代理下的设置( Tab ),
  4. uncheck Use Android studio HTTP proxy setting取消选中Use Android studio HTTP proxy setting
  5. click Apply点击应用
  6. Restart / cold boot your emulator.重启/冷启动你的模拟器。

This should fix the internet connectivity issue on your emulator.这应该可以解决您的模拟器上的互联网连接问题。

我不知道这是否可以帮助任何人,对我有用的是将模拟器的android设置上的日期和时间设置为正确的(当前)日期和时间,看起来很奇怪。

One of the quick and easiest way to solve this is choose a device with API 29 or below , there is some issue on higher API for the inte.net.解决此问题的最快速、最简单的方法之一是choose a device with API 29 or below ,更高的 API 存在一些问题。 The DNS thing was not working for me, so I tried degrading the device API level, and chrome, etc. started working. DNS 对我不起作用,所以我尝试降低设备 API 级别,chrome 等开始工作。 My application however was able to use the inte.net as we were able to fetch the data from BackEnd on higher API but having chrome issues testing some other functionality.然而,我的应用程序能够使用 inte.net,因为我们能够从更高的 API 上的后端获取数据,但在测试其他一些功能时遇到 chrome 问题。

For me, I went to the connectivity settings in emulator and disconnected Android WiFi .对我来说,我去了模拟器中的连接设置并断开Android WiFi Then inside this, I pressed Forget Connection .然后在里面,我按下了Forget Connection Now again connecting to the same WiFi solved the issue.现在再次连接到同一个 WiFi 解决了这个问题。 Quickest way to resolve this I think!我认为解决这个问题的最快方法!

I've been having this issue for the past 8 hours, figuring out a way to solve it.在过去的 8 小时里,我一直遇到这个问题,想办法解决它。 It happened after my house had a power outage.这发生在我家停电之后。 My emulator would not longer connect to my pc's internet.我的模拟器不再连接到我的电脑的互联网。 I tried every solution here.我在这里尝试了所有解决方案。 The changing DNS to 8.8.8.8 worked, but I didn't want to route all my traffic through google.将 DNS 更改为 8.8.8.8 有效,但我不想通过谷歌路由我的所有流量。

What FINALLY worked was.最终起作用的是。 I know this is insane, but unplugging my wifi router/modem.我知道这很疯狂,但拔掉了我的 wifi 路由器/调制解调器。 One quick unplug and replug fixed this issue.快速拔出并重新插入即可解决此问题。 I TRIED EVERYTHING on this SO question and 5 other questions.我在这个 SO 问题和其他 5 个问题上尝试了一切。 I even redownloaded Android Studio and the Emulators.我什至重新下载了 Android Studio 和模拟器。 None of it worked.都没有奏效。 Try unplugging your router/modem.尝试拔下路由器/调制解调器。

Finally, I had to delete the .android folder and create new one.最后,我不得不删除.android文件夹并创建一个新文件夹。 It seems that the files got corrupted文件似乎已损坏

I solved this after 8 or 9 days.我在 8 或 9 天后解决了这个问题。 Just uninstall android emulator SDK(from SDK manager) and then reinstall android emulator SDK.只需卸载 android 模拟器 SDK(从 SDK 管理器),然后重新安装 android 模拟器 SDK。 in 8 or 9 days i tried :在 8 或 9 天内,我尝试了:

1.new windows setup
2.uninstall and install android studio
3.change windows sharing setting
4.change DNS server addresses
5.delete and create some AVDs
6.delete .android folder and create new one etc.

转到您的适配器设置并将 dns 更改为谷歌的 8.8.8.8,它会工作,它对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM