![](/img/trans.png)
[英]How to create and use React Native with Android using an offline bundle
[英]Cannot create offline bundle for react native (iOS)
嗨,我正在嘗試創建一個離線捆綁包,用於反應原生iOS,以便使用以下代碼進行測試
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios
執行此操作后,我嘗試使用命令react-native run-ios --configuration=release
應用程序,一旦應用程序打開並立即崩潰。 所以我這次使用本地開發服務器打開應用程序時使用react-native run-ios
,如果我終止開發服務器,那么我將收到Unhandled JS Exception錯誤。 對於Android,我嘗試了以下步驟使其工作。
mkdir android/app/src/main/assets
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
react-native run-android
即使我終止本地開發服務器,該應用程序也可以在Android中運行。 任何有關為iOS構建離線捆綁包的幫助都表示贊賞。
編輯1:
使用該命令捆綁iOS之后
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios
我能夠在iOS目錄中生成main.jsbundle ,然后按照以下步驟操作。
刪除了所有App Transport Security Settings
並在Info.plist文件中添加了Allow Arbitrary Loads(true)
。
編輯了Run Edit Scheme to Release
更改了jsCodeLocation
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@“index”fallbackResource:nil];
至
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
執行上述步驟后,我收到以下錯誤
File /Users/jeffreyrajan/Library/Developer/Xcode/DerivedData/app_prod-fnewtufemaynsoedmhggmfjynoti/Build/Products/Release-iphonesimulator/app_prod.app/main.jsbundle does not exist. This must be a bug with
+ echo 'React Native
這是項目結構
當前版本 :
似乎運行bundler命令的構建腳本無法正確處理文件路徑中的空白字符。 我可以從您發布的屏幕截圖中看到,項目的路徑在React-Native Projects
目錄中包含一個空格字符。
如果將目錄重命名為例如React-Native-Projects
,則歸檔構建將正常工作。
通常,將目錄和文件名限制為字母數字字符是一種很好的開發人員慣例,因為許多Unix工具需要轉義其他字符類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.