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

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


当前回答

我也遇到过这个问题。 我所做的就是强制关闭我设备上的应用,然后打开另一个控制台并运行

react-native start

然后我从设备上再次打开应用程序,它又开始工作了。

编辑:如果你通过USB使用android设备,并且拔掉了USB插头,或者你的电脑处于休眠状态,你可能需要先运行

adb reverse tcp:8081 tcp:8081

其他回答

它“随机”出现了这个问题,我花了一段时间才意识到我的场景中哪里出了问题。

在我更新到React-native-cli 2.0.1后,有一条消息输出到日志中,帮助我挖掘并找到根本原因:

JS服务器无法识别,继续构建…

在研究了一些链接后,我发现了这个:

无法识别JS服务器

因为我在windows上,我运行netstat,发现我的VLC播放器也在8081端口上运行,导致了这个问题。 所以,在我的情况下,如果我启动vlc服务器之前的反应本机服务器,它不会工作。

在之前版本的react-native-cli中没有输出相同的日志消息,使其无声地失败。

TL, DR:检查与包管理器(默认为8081)相同的端口上是否有任何东西正在运行

当你运行react-native run-android时,请检查是否有以下错误: adb服务器版本(XX)不匹配此客户端(XX);杀死……

在这种情况下,确保/usr/local/opt/android-sdk/platform-tools/adb和/usr/local/bin/adb指向同一个adb

在我的情况下,一个指向/Users/sd/Library/Android/sdk/platform-tools/adb (Android sdk),但另一个指向/usr/local/ caskroom /Android -platform-tools/26.0.2/platform-tools/adb (Homebrew)

问题已经修复后,他们都指向/Users/sd/Library/Android/sdk/platform-tools/adb (Android sdk)

我也有同样的问题。当我通过create-react-native-app AwesomeProject创建一个react原生项目时,它在手机上的Expo应用程序中工作得很好。在那之后,我想用那个快速启动项目来开发我的项目,得到了和你一样的错误。

经过一些研究,我发现最好用react-native init AwesomeProject启动新项目(所有设置都在react native docs中)然后运行以下命令:

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

这应该会修复bundle的问题(——dev false没有显示警告)

你需要做的就是让app在你的虚拟/真实设备上运行:

react-native run-android

它应该能正常工作。至少对我有用。

对我来说,问题是“adb”不被识别-检查这个答案。

要修复此问题,将C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools添加到环境变量中

因为你使用的是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.