【发布时间】:2018-09-05 01:23:03
【问题描述】:
使用react-native run-android 运行应用程序时,它连接到 10.0.2.2:8081 而不是 localhost:8081 并且无法调试。
有谁知道如何修复它以连接到本地主机?
【问题讨论】:
标签: react-native android-emulator react-native-android react-native-debugger
使用react-native run-android 运行应用程序时,它连接到 10.0.2.2:8081 而不是 localhost:8081 并且无法调试。
有谁知道如何修复它以连接到本地主机?
【问题讨论】:
标签: react-native android-emulator react-native-android react-native-debugger
在 MAC 上,我通过以下方式解决了它:
Cmd + M
localhost:8081
react-native run-android
调试器现已连接!
希望它能帮助其他人:)
【讨论】:
adb shell input keyevent 82
您可以尝试通过菜单上的Dev Settings > Debug server & host port for device 来更改它,您可以访问摇动设备或运行adb shell input keyevent 82 命令在终端中
【讨论】:
只需运行端口转发
adb -s emulator-5554 reverse tcp:8081 tcp:8081
或者你的 api 服务器到端口 5000
adb -s emulator-5554 reverse tcp:5000 tcp:5000
【讨论】:
如果您创建了 network_security_config.xml 文件以允许硬件设备连接,这可能是问题的根源。只需在该文件中添加 localhost 和 10.0.2.2 即可。
例如。 network_security_config.xml 文件:
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="false">localhost</domain>
<domain includeSubdomains="false">10.0.2.2</domain>
<domain includeSubdomains="false">192.168.0.12</domain>
</domain-config>
<base-config>
<trust-anchors>
<certificates src="system"/>
<certificates src="user"/>
</trust-anchors>
</base-config>
</network-security-config>
【讨论】: