我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
当前回答
照着做,对我有用。
https://github.com/react-community/lottie-react-native/issues/269
进入你的项目目录,检查这个文件夹是否存在android/app/src/main/assets i)如果它存在,那么删除两个文件即index.android.bundle和index.android.bundle.meta ii)如果assets文件夹不存在,那么在那里创建assets目录。
从您的根项目目录做 CD android && ./gradlew clean
最后,导航回根目录,检查是否有一个名为index.js的条目文件 i)如果只有一个文件,即index.js,则执行以下命令 React-native bundle——platform android——dev false——entry-file index.js——bundle-output android/app/src/main/assets/index.android。Bundle——assets-dest android/app/src/main/res
ii)如果有两个文件,即index.android.js和index.ios.js,那么运行这个 React-native bundle——platform android——dev false——entry-file index.android.js——bundle-output android/app/src/main/assets/index.android. jsBundle——assets-dest android/app/src/main/res
现在运行react-native run-android
其他回答
对于这个问题,我只需要运行:
react-native start
then
adb reverse tcp:8081 tcp:8081
在命令行上。然后我可以运行:
react-native run-android
所以我不会浪费时间去跑:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
每一次。
在命令之前使用NPX对我来说是有效的,命令就像下面这样。
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
为什么我们使用npx,这里是npx和npm之间的区别?
如果在运行react-native run-android命令时,跟踪的第二行是
JS server not recognized, continuing with build...
这意味着应用程序的打包器无法启动,如果没有一些额外的步骤,应用程序将无法加载。注意,跟踪的结尾仍然报告成功:
BUILD SUCCESSFUL
问题可能是端口冲突(在我的情况下,我完全忘记了默认的IIS站点)。该问题的另一种表现形式是无法在Chrome中打开http://localhost:8081/debugger-ui URL。
一旦端口冲突得到解决,跟踪就会报告
Starting JS server...
然后一个额外的Node窗口会打开(Node…cli.js start),应用程序将成功加载/重新加载。
之后,你应该能够打开调试控制台在Chrome与http://localhost:8081/debugger-ui。
在我的例子中,我已经从MainApplication.java中删除了以下一行。(这是我之前错误添加的):-
进口com.facebook.react.BuildConfig;
之后,清洁项目和点击命令
react-native运行android
我不是在真正的设备上遇到这个问题,而是在模拟器上遇到的。在尝试使用android studio运行代码之前,我通过在终端中运行react-native start来修复它。在终端中运行react-native run-android时,我从未遇到过这个问题。