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

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


当前回答

如果这些方法都不适合你,试试下面的方法:

我发现我的<根>/android/app/build/intermediates/assets/debug文件夹是空的,通过运行cd android && ./gradlew assembleDebug没有创建那些所需的文件,这些文件后来被javascript线程在我们的react原生应用程序中使用。

我手动运行了以下命令,调试构建命令应该在理想情况下创建。

node node_modules/react-native/local-cli/cli.js bundle --platform android --dev true --reset-cache --entry-file index.android.js --bundle-output /<path to dir>/android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest /<path to dir>/android/app/build/intermediates/res/merged/debug

在运行这些命令后,我发现在这个目录下有两个bundle文件<root>/android/app/build/intermediates/assets/debug

然后我再次运行cd android && ./gradlew installDebug我的应用程序重新开始工作。

将调试更多,并将更新实际上失败的内容。

其他回答

我的方法是:

react-native start

之后在您的设备中使用:

click to Reload.

在console react-native中,它将获取js bundle data。

当你运行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)

重启genymotion 运行react-native Run -android 问题解决了

因为你使用的是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运行android React-native start -reset-cache,

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

npx react-native run-android

它运行得很好。