ReactNative真机运行时8081端口被占用解决方案

ReactNative环境搭建完毕后使用真机调试时

react-native run-android后,build成功,但是最后提示如下信息


Running F:\android-studio-ide-182.5105271-windows\android-sdk-windows/platform-tools/adb -s e51a670 reverse tcp:8081 tcp:8081
error: cannot bind to socket
Could not run adb reverse: Command failed: F:\android-studio-ide-182.5105271-windows\android-sdk-windows/platform-tools/adb -s e51a670 reverse tcp:8081 tcp:8081
Starting the app on e51a670 (F:\android-studio-ide-182.5105271-windows\android-sdk-windows/platform-tools/adb -s e51a670 shell am start -n com.firstrntest/com.firstrntest.MainActivity)...
Starting: Intent { cmp=com.firstrntest/.MainActivity }


查看端口状态,8081被node占用,运行起来的服务也要使用8081端口

解决方法是将

react-native start命令改为react-native start --port 端口号

react-native run-android命令改为react-native run-android --port 端口号

当然可以直接运行react-native run-android --port 端口号  这个命令node会自动启动。


之后使用adb命令,映射端口号

adb reverse tcp:9999 tcp:8081

问题解决!
 

你可能感兴趣的:(ReactNative真机运行时8081端口被占用解决方案)