尝试在Android 4.4.2上创建一个反应原生项目,我得到了这个错误屏幕

却找不到解决的办法。我尝试重新启动packager,重新连接设备,甚至重新安装react native并开始新的项目。在6.0.0和更高版本上,它工作得很好。


当前回答

当我第一次开始使用React Native时,我也得到了这个,使用物理设备。如果是这样的话,你需要在开始之前做一些额外的事情。你必须在React Native的“Dev Settings”中输入一些关于你的开发机器的信息。

当你看到错误时,摇动你的设备。一个对话框将弹出,最后一个选项将是“开发设置”。选择“调试服务器热和设备端口”,输入您的本地IP和使用的端口(通常是8081)。

见https://facebook.github.io/react-native/docs/running-on-device-android.html的最后一段

其他回答

因为你使用的是Android < 5.0,所以你不能使用默认的adb反向方法,但是Facebook已经添加了官方文档来通过Wi-Fi连接到开发服务器,这将支持你的版本。引用MacOS的说明,但也有Linux和Windows的说明:

Method 2: Connect via Wi-Fi You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding. You can find the IP address in System Preferences → Network. Make sure your laptop and your phone are on the same Wi-Fi network. Open your React Native app on your device. You'll see a red screen with an error. This is OK. The following steps will fix that. Open the in-app Developer menu. Go to Dev Settings → Debug server host for device. Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081). Go back to the Developer menu and select Reload JS.

当我第一次开始使用React Native时,我也得到了这个,使用物理设备。如果是这样的话,你需要在开始之前做一些额外的事情。你必须在React Native的“Dev Settings”中输入一些关于你的开发机器的信息。

当你看到错误时,摇动你的设备。一个对话框将弹出,最后一个选项将是“开发设置”。选择“调试服务器热和设备端口”,输入您的本地IP和使用的端口(通常是8081)。

见https://facebook.github.io/react-native/docs/running-on-device-android.html的最后一段

我也得到了这个错误,真的很困惑。因为不是所有的答案都有效。 就在添加adb到路径之后。

在设置中,转到隐私>本地网络,查看请求访问的每个应用程序的列表。 我通过允许我的应用程序访问本地网络来解决这个问题。 (试图从我的mac m1上运行在同一wifi的实体iPhone设备上)。

有人建议用下面这个

react-native运行android React-native start -reset-cache,

但在我的例子中,我只是关闭cli命令提示窗口,并使用以下命令。

npx react-native run-android

它运行得很好。