You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助:Android模拟器与React Native打包器连接开发服务器失败

Fixing Android Emulator Failed to Connect to React Native Dev Server (No Env Changes)

Hey there, sorry to hear you're hitting this frustrating connection issue—especially when you swear nothing in your setup changed. I’ve been in your shoes before, so let’s walk through the most likely fixes step by step:

1. Verify Localhost Access from the Emulator

Android emulators don’t use localhost the same way your computer does; they map to 10.0.2.2 for your host machine’s loopback.

  • Open the emulator’s browser and navigate to http://10.0.2.2:8081
    • If the Metro bundler page loads, the network path is good—skip to step 3.
    • If not, your host’s 8081 port is either blocked or the dev server isn’t running.

2. Restart the Dev Server (With Cache Reset)

Sometimes the Metro bundler silently crashes or gets stuck with stale cache, even if you didn’t touch anything:

  • Kill any existing Metro processes (check your task manager/activity monitor if needed)
  • Run this command in your project root:
    npx react-native start --reset-cache
    
  • Wait for the server to fully start, then try reloading the app in the emulator.

3. Reset Emulator Network Proxy

Emulators sometimes glitch and set a wrong proxy without warning:

  • Open the emulator’s Settings > Network & Internet > Wi-Fi
  • Long-press the connected Wi-Fi network, select "Modify network"
  • Tap "Advanced options" and set "Proxy" to None
  • Save the changes and reload the app.

4. Refresh ADB Connection

Flaky ADB links can block communication between your computer and emulator:

  • Open a terminal and run:
    adb kill-server
    adb start-server
    
  • Then re-run your project:
    npx react-native run-android
    

5. Check Firewall/Antivirus Interference

Even if you didn’t change settings, automatic updates to your firewall or antivirus might suddenly block port 8081:

  • Temporarily disable your firewall/antivirus (only for testing!)
  • If the connection works, add an exception for node.exe (which runs Metro) or port 8081 in your security tool.

6. Manually Set Dev Server Host in the Emulator

If the app is still failing to find the server, force it to use the correct address:

  • Shake the emulator (or press Ctrl+M on Windows/Linux, Cmd+M on Mac) to open the developer menu
  • Tap Dev Settings > Debug server host & port for device
  • Enter 10.0.2.2:8081 and save
  • Go back to the developer menu and tap Reload JS

7. Clean Android Build Cache

Stale build artifacts can sometimes cause unexpected connection issues:

  • Navigate to your project’s android folder:
    cd android
    ./gradlew clean
    
  • Return to the root folder and re-run the project.

If none of these work, double-check that you haven’t accidentally modified your metro.config.js file (even a tiny typo can break things). But more often than not, one of the steps above will get you back up and running!

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:45:01