当我运行 react-native run-android
时,它给了我以下错误:
Could not connect to development server
- 包服务器正在运行,我可以直接从浏览器访问它 在我的移动设备上。
- 我的 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/