- 禁用模拟器的防火墙:在模拟器中打开设置 - 高级选项 - 防火墙,将其禁用或配置允许应用程序对网络进行访问。
- 确保模拟器和主机之间的网络连接正常:在模拟器中执行命令 adb shell ping <主机IP地址>,检查是否能够正常连接。
- 在模拟器上运行如下命令,重置网络配置:
adb shell su root iptables --flush
adb shell su root iptables --table nat --flush
adb shell su root iptables --delete-chain
adb shell su root iptables --table nat --delete-chain
- 在模拟器中设置 DNS 服务器:在模拟器中打开设置 - WIFI,长按所连接的网络,选择“修改网络”,在“IP设置”中选择“手动”,填写本地 DNS 服务器的 IP 地址。
示例代码:
adb shell su root iptables --flush
adb shell su root iptables --table nat --flush
adb shell su root iptables --delete-chain
adb shell su root iptables --table nat --delete-chain