轉載地址:https://blog.csdn.net/jasonzds/article/details/78747524
新建項目
react-native init TestApp
1
運行項目
react-native run-android
1
不好意思,錯誤馬上就到了
錯誤1:unable to load script from assets ‘index.android bundle’ ,make sure your bundle is packaged correctly or youu’re runing a packager server
解決辦法
1,在 android/app/src/main 目錄下創建一個 assets空文件夾
mkdir android/app/src/main/assets
1
2,在項目根目錄運行
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/
1
注意了,是編譯index.js而不是index.android.js,因爲react-native新版本已經沒有index.android.js和index.ios.js兩個文件了,只有一個index.js文件,所以要編譯index.js
會發現 assets文件夾下多出兩個文件
index.android.bundle index.android.bundle.meta
1
3,重新react-native run-android
*錯誤2:could not connect to development server.
Try the follwing to fix the issue:*
解決辦法:
重新編譯index.js文件(走一遍錯誤一中的第2部),在重新運行react-native run-android
雙擊R鍵刷新android模擬器
另外運行ios時,如果想指定某個模擬器
react-native run-ios –simulator “iPhone X”
查看iOS設備:在終端中輸入
xcrun simctl list devices
---------------------
作者:_摩西_
來源:CSDN
原文:https://blog.csdn.net/jasonzds/article/details/78747524
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!