I am developing a simple app using React Native. I am testing it on Android device. I have created a Node.js server to listen to the requests, it is running at http://localh
Since your Android device has an IP of its own, you need to point the URL to your computers IP address instead of just localhost. For example fetch('http://192.168.0.2:3333/')
.
Use the reverse command of the Android Debug Bridge tool (adb):
adb reverse <remote> <local> - reverse socket connections.
reverse specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
For example:
adb reverse tcp:3333 tcp:3333
This makes localhost:3333
accessible from your device. You can also use different ports. For example:
adb reverse tcp:8081 tcp:3333
This will redirect the device port 8081 to the local port 3333.