簡體   English   中英

無法為本機創建脫機捆綁包(iOS)

[英]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,我嘗試了以下步驟使其工作。

  1. mkdir android/app/src/main/assets
  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
  3. 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 ,然后按照以下步驟操作。

  1. 刪除了所有App Transport Security Settings並在Info.plist文件中添加了Allow Arbitrary Loads(true)

  2. 編輯了Run Edit Scheme to Release

  3. 更改了jsCodeLocation

    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@“index”fallbackResource:nil];

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  1. 產品 - > 構建

執行上述步驟后,我收到以下錯誤

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

這是整個錯誤的屏幕截圖 在此輸入圖像描述

這是項目結構

在此輸入圖像描述

當前版本

  • 反應:16.0.0
  • React Native:0.51.0
  • Xcode中:9.2

似乎運行bundler命令的構建腳本無法正確處理文件路徑中的空白字符。 我可以從您發布的屏幕截圖中看到,項目的路徑在React-Native Projects目錄中包含一個空格字符。

如果將目錄重命名為例如React-Native-Projects ,則歸檔構建將正常工作。

通常,將目錄和文件名限制為字母數字字符是一種很好的開發人員慣例,因為許多Unix工具需要轉義其他字符類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM