请求协助:Android模拟器与React Native打包器连接开发服务器失败
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+Mon Windows/Linux,Cmd+Mon Mac) to open the developer menu - Tap Dev Settings > Debug server host & port for device
- Enter
10.0.2.2:8081and 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
androidfolder: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

