如何让我的 Android 模拟器使用我计算机的 VPN 接口?
我的公司需要 VPN 来连接到我们的开发系统,这是我第一次尝试在家中开发 Android 应用程序。结果模拟器不想使用 VPN 接口,因此即使我在连接 VPN 的笔记本电脑上可以连接到我们的开发系统,但在其上运行的模拟器却无法连接。
我想到了 3 个解决方案:
- 在模拟器上运行 VPN 客户端,但我希望有一个更简单的解决方案 比在
- 本地计算机上设置代理服务器
- 在本地计算机 2 和 3 上转发端口
可能可行,但我仍然想知道是否有简单的方法来获得模拟器使用 VPN 接口,无需解决方法。
我正在运行 OS X 10.7,并且我已经尝试使用网络>>设置服务顺序来调整接口优先级顺序。
我想我可以掸去旧戴尔的灰尘并在那里尝试一下,但我希望得到相同的结果。
My company requires VPN to connect to our dev systems and for the first time I'm trying to work on an android app from home. Turns out the emulator doesn't want to use the VPN interface so even though I have connectivity to our dev systems on my VPN-connected laptop the emulator that's running on it does not.
I have thought of 3 solutions to this:
- run a VPN client on the emulator, but I was hoping for a simpler solution than that
- setting up a proxy server on my local machine
- forwarding a port on my local machine
2 and 3 can probably work, but I'd still like to know if there is an easy way to get the emulator to use the VPN interface without a workaround.
I'm running OS X 10.7 and I've already tried adjusting the interface priority order with network>>set service order.
I suppose I can dust off the old dell and try it there, but I would expect the same results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
首先启动您的 VPN 连接,然后重新启动模拟器,现在模拟器应该使用主机 VPN 连接。
根据 android 文档,这主要是由于 DNS 问题
:启动时,模拟器会读取系统当前使用的 DNS 服务器列表。然后,它会在此列表中存储最多四台服务器的 IP 地址,并根据需要在模拟地址 10.0.2.3、10.0.2.4、10.0.2.5 和 10.0.2.6 上为它们设置别名。
First start your vpn connection and then restart the emulator, now the emulator should use the host vpn connection.
it's mostly because of the DNS issue, according to the android doc:
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.
我遇到了这个问题,并尝试了 dns 设置,但无法解决。正如 @machado 在下面的评论部分中所说,您应该通过“立即冷启动”选项来启动模拟器。我希望这有帮助。
I encountered this issue and tried something on dns settings but I could not solve it. As @machado said in the comment section below you should boot the emulator via "Cold Boot Now" option. I hope this helps.
我在 Mac 上所做的只是确保选中“通过 VPN 发送所有流量”。
在网络首选项中选择 VPN 连接并单击“高级”后,您将看到此设置。
适合我的情况,但可能不取决于您连接的 VPN 类型。
What I do on my mac is just make sure 'send all traffic over vpn' is checked.
You'll find this setting after you click advanced while having your vpn connection selected in network preferences.
Works well for my situation, but may not depending on the type of VPN you're connecting to.
我遇到了同样的问题,并在 Android 模拟器启动并连接到互联网后通过连接到 cisco vpn 解决了该问题。
在 Windows 7 中适合我
I had the same issue and solved it by connecting to cisco vpn after the android emulator has started and connected to the internet.
Works for me in windows 7
我在 Windows 上设置了 VPN 连接。然后我启动了模拟器。模拟器和我电脑上的所有内容开始使用该 VPN 连接。
I setup a vpn connection on Windows. Then I started the emulator. The emulator and everything on my pc started to use that vpn connection.
解决方案取决于你的环境,对我来说:win10+V2ray(VPN客户端)+android studio。
解决方案有效:
我发现 位于 V2ray 的底部。
我想 HTTP 的默认端口是 1081,socks 的默认端口是 1080,所以我都尝试了。
这里 1081 有效。
如果您使用其他 VPN 客户端,请尝试更换您的端口,也许会起作用。
The solution depends on your environment, for me: win10+V2ray(VPN client)+android studio.
The solution works:
I found this at the bottom of the V2ray.
I suppose the default port for HTTP is 1081, and socks is 1080, so I tried both.
And here 1081 works.
If you use another VPN client, try to replace your port, and it may work.
该线程太旧了,但是,它可能对某人有帮助 -
我花了很多时间试图解决同样的问题(在 Android 13/14 模拟器上),我尝试了冷启动、重置数据以及我可以在 SO 或其他地方找到的所有选项。没有什么对我有用。
然后我遇到了下面这 2 个解决方案,它们都对我有用 -
选项 1:每次冷启动模拟器时都需要执行此操作
我不小心关闭了模拟器内的 Android Wi-Fi。之后,我的模拟器可以通过我的笔记本电脑的 VPN 进行连接。
选项 2:问题是 Android 指定的 IP 地址 10.0.xx 干扰了 VPN IP 范围
我将 Android Wifi DHCP 设置更改为不使用 Android 模拟器 IP 和网关配置,而是仅使用我的网络 IP 地址和静态网关。这也有效。我认为这是可行的,因为现在 Android 无法通过其默认范围进行路由 - 就像关闭 AndroidWifi 一样。
This thread is so old, however, it might be helpful to someone -
I spent so much time trying to fix this same issue (On Android 13/14 Emulators), I tried cold boot, resetting the data, and all the options I could find in the SO or other places. Nothing worked for me.
Then I came across these 2 solutions below, both worked for me -
Option 1: This needs to be done everytime when we cold boot emulator
I accidentally turned off the Android Wi-Fi inside the Emulator. After that, my emulator could connect through my Laptop's VPN.
Option 2: Issue was Android given IP Address of 10.0.x.x interfering with VPN IP range
I changed the Android Wifi DHCP setting to not use Android Emulators IP and Gateway config, instead I just used my network Ip Address and Gateway static. That also worked. I think this works because now Android cannot route through its default range - just like turning off the AndroidWifi.