You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

如何在Android Studio模拟器中使用电脑配置的VPN?

Fixing Android Emulator VPN Access for Campus Network Auth

Hey there, I totally get how annoying it is when your host VPN works perfectly but the emulator refuses to connect—especially when your app’s auth is locked to the campus network. Let’s go through some tried-and-true fixes that usually get this sorted:

1. Force the Emulator to Use Your VPN’s DNS Servers

Emulators often don’t automatically pick up VPN DNS settings, which can block access to campus-only resources. Here’s how to fix that:

  • Open your terminal/command prompt and navigate to your Android SDK’s emulator folder (e.g., ~/Android/Sdk/emulator on macOS, C:\Users\YourName\AppData\Local\Android\Sdk\emulator on Windows).
  • Launch your emulator with the DNS flag pointing to your campus VPN’s DNS (find this in your host’s network settings while connected to VPN):
    emulator -avd Your_Emulator_Name -dns-server 123.45.67.89
    
    Replace Your_Emulator_Name with the name of your AVD (check Android Studio’s AVD Manager) and 123.45.67.89 with your VPN’s actual DNS IP.

2. Set Up Proxy Directly in the Emulator

Changing Android Studio’s proxy settings doesn’t always apply to the emulator itself. Let’s configure the proxy inside the emulator:

  • Fire up the emulator, go to Settings > Network & Internet > Wi-Fi.
  • Long-press the default "AndroidWifi" network and tap Modify network.
  • Check "Advanced options", set Proxy to "Manual".
  • Enter your host machine’s local IP (like 192.168.1.100) as the proxy host, and the port your VPN uses (look this up in your VPN client’s settings).
  • Save, then restart the emulator and test your app.

3. Adjust Emulator Network Mode

The default NAT network mode can clash with some VPNs. Try switching to a more direct network setup:

  • Open Android Studio’s AVD Manager, click the pencil icon to edit your emulator.
  • Go to the Advanced Settings tab.
  • Under "Network", change the Network Type to "Bridge" (if available) or "Host-only".
  • Save the changes and restart the emulator. This makes the emulator act like a separate device on your local network, which often plays nicer with VPNs.

4. Check Campus VPN Restrictions

Some campus VPNs block traffic from virtual machines or emulators. You might need to:

  • Reach out to your campus IT team to confirm if emulators are allowed through the VPN.
  • If possible, add the emulator’s network adapter to your VPN’s trusted devices list (check your VPN client’s settings for this).

5. Reset Emulator Network Settings

Cached network configs can cause weird issues. Let’s wipe them:

  • In the emulator, go to Settings > System > Reset > Reset Wi-Fi, mobile & Bluetooth.
  • Confirm the reset, then reconnect your host to VPN and test your app’s auth again.

If all else fails, try creating a new AVD with a different Android version—sometimes older emulator images have better VPN compatibility than the latest ones.

内容的提问来源于stack exchange,提问作者Borbat

火山引擎 最新活动