React-Native搭建報錯:Unable to load script.Make sure you're either running a metro server or that ....
報錯
Unable to load script.Make sure you're either running a metro server
(run 'react-native start' ) or that
your bundle 'index.android.bundle' is packaged correctly for release.
原因
我自己這裏報錯原因是沒有找到index.android.bundle。
解決方法
方法一
創建android/app/src/main/assets文件夾
執行命令
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
重新執行
react-native run-android
參考文檔:https://stackoverflow.com/questions/44795384/unable-to-load-script-from-assets-index-android-bundle-make-sure-your-bundle
方法二
修改 項目目錄/android/app/build.gradle裏
主要是設置bundleInDebug等於true,使得開發時也會打包index.android.bundle。
參考文檔:https://github.com/facebook/react-native/issues/22076