android - 适用于 Android 的 React-Native:无法连接到开发服务器
问题描述
我正在为现有项目设置 react native android。我按照官方入门页面的说明进行操作。当我运行时,我可以在模拟器中打开应用程序react-native run-android
。该应用程序运行完美。但问题是,当我使用双击R
键重新加载它时,它会抛出错误Could not connect to development server
。
在模拟器和真实设备上都出现此错误
我尝试过的解决方案:
- 在同一个 wifi 上运行真实设备和 Macbook。
- 在Android设备/模拟器中设置macbook的IP地址和端口
Dev Setting -> Debug server host & port for device
- 跑步
adb reverse tcp:8081 tcp:8081
仍然没有运气。
当我使用打开开发人员选项CMD + D
并单击时Debug JS Remotely
,它会引发不同的错误:
Unable to connect to remote debugger. CLEARTEXT communication to 192.x.x.x not permitted by network security policy.
解决方案
这个答案解决了我的问题:https ://stackoverflow.com/a/53158627/2630184
似乎这是Cleartext
在 Android Pie 上的问题,因为我也提到了这个问题,即在单击时显示明文错误Debug js remotely
。
添加android:usesCleartextTraffic="true"
AndroidManifest.xml,为我解决了这个问题。
<application
android:name="com.example.app"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
推荐阅读
- python - 未使用的字节应该在左边还是右边
- android - 使用 Chaquopy 将 Python 中的 PyObject 转换为 Android 中的二维数组
- typescript - 为什么 TypeScript 的 IterableIterator<> 和 Generator<> 泛型略有不同?
- pytorch - pytorch 中嵌入的加权求和
- c++ - 仅调用某些模板类成员函数有效
- blazor - 在 Blazor 服务器端使用 CancellationTokenSource 实现去抖动
- reactjs - React-Select:保持编辑模式() 选择后(输入)
- autodesk-forge - 场景更新()与无效()
- c# - 什么是 C# 中的 SafeFileHandle,我应该什么时候使用它?
- git - 无法推送到 GitHub 上的远程存储库