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. After upgrading to version 2.3 of Android Studio, my emulator is no longer able to access the internet. I even uninstalled/reinstalled Android Studio 2.3 from scratch and created a new emulator, and I am still getting the same error. This is not an app problem. I can't even access the internet from Chrome, and I wasn't having this problem last week. The message that I get says that the server DNS address could not be found -- 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 internet. Below is an image of my emulator when I try to use Chrome to search for "Google".
当前回答
最后,我不得不删除。android文件夹并创建一个新的。看来文件损坏了
其他回答
窗户 在所选网络连接的“TCP/IP属性”窗口中指定DNS设置。
举例:在Windows 10操作系统下修改DNS服务器设置
进入控制面板。 单击“网络和Internet”>网络和共享中心>更改适配器设置。 选择需要配置谷歌Public DNS的连接。例如:
要更改以太网连接的设置,右键单击以太网接口,选择“属性”。 要更改无线连接的设置,右键单击Wi-Fi界面并选择属性。 如果系统提示您输入管理员密码或确认,请键入密码或提供确认信息。
选择Networking选项卡。在“此连接使用以下项目”下,选择“Internet协议版本4 (TCP/IPv4)”或“Internet协议版本6 (TCP/IPv6)”,然后单击“属性”。
单击“高级”,选择“DNS”页签。如果那里列出了任何DNS服务器IP地址,请将它们写下来以备将来参考,并将它们从这个窗口中删除。
单击OK。
勾选“使用以下DNS服务器地址”。如果“首选DNS服务器”或“备选DNS服务器”中存在IP地址,请将其记录下来,以便后续查询。
替换为谷歌DNS服务器的IP地址。
对于IPv4: 8.8.8.8和/或8.8.4.4。 IPv6: 2001:4860:4860::8888和/或2001:4860:4860::8844。 仅IPv6:您可以使用谷歌Public DNS64代替前面提到的IPv6地址。 测试你的设置是否正常工作;请参见测试您的新设置。
对要更改的其他网络连接重复此过程。
macOS DNS设置在“网络”窗口中指定。
举例:在macOS 10.15操作系统下修改DNS服务器设置
Click Apple menu > System Preferences > Network. 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. For example: To change the settings for a Wi-Fi connection, select Wi-Fi, and click Advanced. To change the settings for an Ethernet connection, select Built-In Ethernet, and click Advanced. Select the DNS tab. 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. For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844. For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point. 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 在大多数现代Linux发行版中,DNS设置都是通过网络管理器配置的。
举例:修改Ubuntu的DNS服务器设置
Click System > Preferences > Network Connections. Select the connection for which you want to configure Google Public 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. 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. If the selected method is Automatic (DHCP), open the dropdown and select Automatic (DHCP) addresses only instead. 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. For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844. For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point. 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.
举例:在Debian服务器上修改DNS服务器设置 编辑/etc/resolv.conf:
sudo vi /etc/resolv.conf
如果出现任何命名服务器行,请写下IP地址以备将来参考。
用或添加以下行替换命名服务器行:
IPv4:
nameserver 8.8.8.8
nameserver 8.8.4.4
For IPv6:
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
对于IPv6,可以使用谷歌Public DNS64代替上述IPv6地址。
保存并退出。
重新启动您正在使用的任何Internet客户机。
测试你的设置是否正常工作;请参见测试您的新设置。
如果您的网络上有PiHole,请确保您的Pi正在工作,并且您可以访问PiHole的web UI。每一次,当我的模拟器突然无法连接到互联网时,都是因为它们中的任何一个出了问题。
我观察到的是,当你切换wifi连接时,android模拟器正在运行。它无法连接到新的wifi。
一个简单的解决方案是重新启动android模拟器。
正如@osama buzdar所指出的,模拟器首先查看的DNS设置可能在/etc/resolv.conf中指定。在我的情况下,macOS Catalina 10.15.7,该文件中有2个地址:第一个是IPv6,第二个是IPv4,由于某种原因,模拟器可能在IPv6上有问题。
然后我编辑文件(sudo vi /etc/resolv.conf),并将IPv4移到文件的第一个条目,在IPv6之前。重新启动模拟器,它工作了。
在尝试了许多这些解决方案之后,我打算删除我当前的AVD并重新制作它,但当我点击AVD上的向下箭头时,我注意到“现在冷启动”。
一时兴起,我试了一下。瞧,我的模拟器又有互联网连接了!
命令行方式
如果你通过命令启动模拟器,传递-no-snapshot-load选项,比如:
%ANDROID_HOME%/emulator/emulator.exe -netdelay none -netspeed full -no-snapshot-load -avd Pixel_2_API_28
或者MacOSX:
$ANDROID_HOME/emulator/emulator -netdelay none -netspeed full -no-snapshot-load -avd Pixel_2_API_28
注意,您可能需要更改-avd Pixel_2_API_28部分(与您自己的虚拟设备名称)。 此外,大多数工具使用ANDROID_HOME环境变量名,因此定义它(如果还没有),但现在ANDROID_ROOT是另一个命名选项。
决定(编辑)
对于那些说为什么不擦除数据重新启动的人。 你每次重启电脑时都重新格式化吗?擦除模拟器上的数据就像对手机进行出厂重置或重新格式化PC上的硬盘驱动器并重新安装操作系统。除非数据完全损坏,否则这是不必要的。
当你关闭模拟器并重新启动它时,它就像将你的电脑置于休眠或睡眠模式。记忆不是被抹去,而是被保存。
冷启动和重启手机或电脑是一样的。它可以重置内存并重新加载。这允许网络模拟以干净的内存启动并正确连接。
所以,不要擦除数据。只是冷启动。如果还是没用,那就擦一下,但要留作最后的手段。
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。