安卓模拟器访问不了网络

Android 2021-09-14 阅读 142 评论 0

问题描述

在 macOS 10.15.5,从命令行中启动模拟器。

% emulator -avd Pixel_XL_API_30

发现访问不了外网,比如域名的访问,就连 hosts 到本地的域名也失败了。但是使用 IP 访问是成功的。adb shell 进去虚拟机,执行 ping 命令也是失败,但是 ping 本地局域网 IP 是成功的。

% adb shell
generic_x86_arm:/ $ ping www.baidu.com
generic_x86_arm:/ $ ping 192.168.8.1

这种情况很像以前电脑出现网络问题,不能浏览网页,但是 qq 却能正常使用。

解决方法

启动模拟器命令,加上 -dns-server 选项,指定 dns 的 IP 地址。此选项将设置模拟器系统的 dns。

% emulator -avd Pixel_XL_API_30 -dns-server 8.8.8.8,114.114.114.114
最后更新 2021-09-14
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });