Android模拟器不能上网的解决方法

我原来一直不用Android的模拟器,因为这东西的多年前的印象真的是很糟糕——启动半个小时,不支持OpenGL。即使后来有了x86镜像,在HAXM的支持下快的飞起,也不想用,因为NDK还要编译x86的。那个时候我一直用网易的MuMu模拟器——只需要编译Armv7的就行了。再后来就是网易的全部Mac App不知道抽了什么风,疯狂写log,直到写满硬盘为止,我就把MuMu给删了,同时也摆脱了这玩意动不动就启动不起来的烦恼。

现在的Android模拟器还是不错的,那就用一下吧。

在Mac上HAXM是不需要装的,即使装了也没用。

https://docs.microsoft.com/zh-cn/xamarin/android/get-started/installation/android-emulator/hardware-acceleration?pivots=macos

先装了一个Oreo(Google Play),什么鬼,用了10G的磁盘空间,即使禁止热启动也没小多少,然后居然不能上网!网上一查,都是说要改DNS,还要root。

好吧,我知道Google的套件就是费空间,装个干净的吧,Q(Android 9.+),反正我也不用Google API,这回好些了,占用4G磁盘。

然后我又装了一个Android 6.0的镜像,占用5.2G磁盘,Android果然是垃圾堆——你会发现随着Android版本的增加,占用磁盘越来越少——或者说Google把原来的福利套件都移除了?

关键是,这个能直接上网!

比较一下就能发现,Android 6.0的镜像没有虚拟WiFi,直接用宿主机来上网

而从Android 7.0开始,虚拟了一个NAT网络,以下截图是Android 9.+的

 

所谓的改DNS的原因就是如下:

 

理由就是,这是个什么见鬼的DNS,反正改一下就能上网了……

但是,即使我认为Android再垃圾,我也不认为测试团队能让这种事情发生——不能上网,并且从7持续到了9。并且,即使改DNS能解决问题,也不是个好方法——如果指向局域网的DNS(基本上就是网关或者路由器的地址),当你换一个环境难道再改一次DNS?

那么这个奇怪的DNS是什么,因为Android的官网不好打开,我复制了一下相关内容:

 

At startup, the emulator reads the list of DNS servers that your system is currently using. It then stores the IP addresses of up to four servers on this list and sets up aliases to them on the emulated addresses 10.0.2.3, 10.0.2.4, 10.0.2.5 and 10.0.2.6 as needed. 

On Linux and OS X, the emulator obtains the DNS server addresses by parsing the file /etc/resolv.conf. On Windows, the emulator obtains the addresses by calling the GetNetworkParams() API. Note that this usually means that the emulator ignores the content of your "hosts" file (/etc/hosts on Linux/OS X, %WINDOWS%/system32/HOSTS on Windows).

When starting the emulator at the command line, you can also use the -dns-server <serverList> option to manually specify the addresses of DNS servers to use, where <serverList> is a comma-separated list of server names or IP addresses. You might find this option useful if you encounter DNS resolution problems in the emulated network (for example, an "Unknown Host error" message that appears when using the web browser).

 

意思就是,模拟器会把宿主机的DNS依次复制到10.0.2.3,10.0.2.4,10.0.2.5,10.0.2.6,按理说这么做没问题啊。于是我打开了系统的DNS

 

但是我的/etc/resolv.conf是这个样子的,难道IPv6优先?系统信息里明明IPv4的地址在前面。

 

原因就很明显了,那个IPv6的DNS是什么鬼,然后我把路由器的IPv6的功能一关,重连WIFI,重启模拟器,问题解决了。

总结:现在国内的IPv6一团麻,根本不知道是个什么情况,干脆先禁用一阵子。

 

转载于:https://www.cnblogs.com/yunteng/p/11044589.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值