React Native条码示例应用执行run-android后出现503错误求助
Hey there, I know how frustrating it is to get your app installed only to hit a 503 error. Let's walk through some practical fixes that should get your barcode sample app up and running:
1. Make Sure Metro Server is Running Properly
Sometimes the Metro bundler doesn't start correctly when you run react-native run-android. Try this:
- Open a new terminal window, navigate to your project root, and run:
npx react-native start - Wait until you see the "Metro waiting on..." message, then go back to your original terminal and re-run
react-native run-android.
2. Clear All Caches (A Common Culprit)
Cached data can often cause unexpected server errors. Run these commands one by one:
- Reset React Native's cache:
npx react-native start --reset-cache - Clean your Android project's build files:
cd android && ./gradlew clean && cd ..
Then try building and running the app again.
3. Verify Device-Metro Connectivity
Your app needs to reach the Metro server on your computer. Here's how to fix connection issues:
- For physical devices: Ensure USB debugging is enabled, then run this command to forward ports:
adb reverse tcp:8081 tcp:8081 - For emulators/physical devices: Open the React Native dev menu (Ctrl+M for emulators, shake your device for physical ones), select "Change Bundle Location", and enter your computer's local IP plus port 8081 (e.g.,
http://192.168.1.5:8081/index.bundle). - Double-check that your device and computer are on the same Wi-Fi network.
4. Check for Port Conflicts
Metro uses port 8081 by default—if another app is using it, you'll get a 503 error:
- Windows: Find the process using 8081:
Kill it with:netstat -ano | findstr :8081taskkill /PID <ProcessID> /F - Mac/Linux: Find the process:
Kill it with:lsof -i :8081kill -9 <ProcessID>
Restart Metro after this.
5. Validate Dependencies & Permissions
- Double-check that your barcode-related libraries (like
react-native-cameraor similar) are installed correctly and compatible with your React Native version. - Ensure your
android/app/src/main/AndroidManifest.xmlincludes the internet permission—this is required for the app to connect to Metro:<uses-permission android:name="android.permission.INTERNET" />
If none of these steps work, try restarting your computer and device—sometimes a fresh start fixes weird connectivity glitches.
内容的提问来源于stack exchange,提问作者Rashiq

