RN android studio打包報錯Unable to load script.Make sure you're either running a metro

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
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章