While running app with react-native run-android
its connecting to 10.0.2.2:8081 instead of localhost:8081 and not able to debug.
Does anyone know how to fix so that it will connect to localhost instead?
Connecting a React Native app to React Native Debugger To connect your app with React Native Debugger, you need to run your app and start debug mode. To start debug mode, shake your mobile device or press Command + Shift + Z or Ctrl + M and choose the debug option. We're all set to begin using React Native Debugger.
Running your React Native applicationInstall the Expo Go app on your iOS or Android phone and connect to the same wireless network as your computer. On Android, use the Expo Go app to scan the QR code from your terminal to open your project. On iOS, use the built-in QR code scanner of the default iOS Camera app.
In Android, we can use the IP 10.0. 2.2 to access computers localhost. In a project, we can use the above logic to decide what baseUrl to use based on the platform. Afterwards, we can use this baseUrl for all APIs.
On MAC I solved it by doing following:
Cmd + M
on emulator screenlocalhost:8081
react-native run-android
Debugger is connected now!
Hope it will help others :)
Just run port forwarding
adb -s emulator-5554 reverse tcp:8081 tcp:8081
OR your api server to port 5000
adb -s emulator-5554 reverse tcp:5000 tcp:5000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With