android - 无法连接到 Android 上的 React Native 开发服务器

标签 android react-native

当我运行 react-native run-android 时,它给了我以下错误:

Could not connect to development server

Error screen

  • 包服务器正在运行,我可以直接从浏览器访问它 在我的移动设备上。
  • 我的 Android 设备已连接到计算机并启用了调试(我 使用 adb devices 命令检查)。
  • 我的 Android 版本是 4.4.4,所以我不能使用 adb reverse 命令。
  • 我已经在 Dev 设置中设置了 ID 地址和端口。
  • USB 调试已开启。
  • 我使用的是 Windows 7。

如何解决这个错误?

最佳答案

就我而言,问题在于 Android 安全策略。根据documentation :

Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

但是应用程序尝试通过 HTTP 访问 Metro Bundler,对吗?这就是为什么它不能。为了启用明文流量,打开您的AndroidManifest.xml并添加 android:usesCleartextTraffic="true"<application>节点。

例如:

<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">

您可以在此 SO 中找到更多解决方案:https://stackoverflow.com/a/50834600/1673320 . OP的问题不同,但相似。

关于android - 无法连接到 Android 上的 React Native 开发服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42064283/

相关文章:

android - 单击第一个 ContextMenu 的 Item 时打开另一个 ContextMenu

android - 从点云生成深度图

android - 将 Alsa 移植到 Android

android - 如何通过 navArgs 将参数传递给详细 ViewModel

java - 在 Android 中从字符串加载图像

ios - 切换到 iMac 后,React-Native 在设备上的构建变得极其缓慢

javascript - 如何在React js中找出带有键的数组元素

javascript - 如何在代码之间使用ActivityIndi​​cator?

javascript - 如何隐藏特定屏幕上的底部标签栏(react-navigation 3.x)

css - 在 react-native 样式表中复制 css border 和 box-shadow 值时遇到问题