Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctl

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_23575795/article/details/81281326

第一种:使用bundle命令:(缺点:后续没办法reload,只能重复生成bundle文件)

1.在Android/app/src/main目录下创建一个空的assets文件夹

2: 在工程根目录下数据bundle命令:

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/

分析:入口文件(--entry-file)可以从Android->app->build.gradle 查看:

project.ext.react = [ entryFile: "index.js" ]

index.android.bundle是用来调用原生控件的js脚本,每次当改变了 index.js,都需要使用上面的代码片段,来及时的更新index.android.bundle,然后打包才可以把新的index.js应用上,所以当没有index.android.bundle文件时,React-Native 项目是无法运行的。

第二种.在IDE的terminal以命令启动(推荐使用这一种):

1.adb devices  (查看连接设备;注意,你只应当连接仅仅一个设备)

2.react-native run-android

可以参考官方文档解决:https://reactnative.cn/docs/0.51/running-on-device-android.html

猜你喜欢

转载自blog.csdn.net/qq_23575795/article/details/81281326