简体   繁体   English

无法为本机创建脱机捆绑包(iOS)

[英]Cannot create offline bundle for react native (iOS)

Hi I was trying to create a offline bundle for react native iOS for testing using the following code 嗨,我正在尝试创建一个离线捆绑包,用于反应原生iOS,以便使用以下代码进行测试

react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

After doing this I tried to run the app using the command react-native run-ios --configuration=release once it is done the app opens and crashes instantly. 执行此操作后,我尝试使用命令react-native run-ios --configuration=release应用程序,一旦应用程序打开并立即崩溃。 So I used react-native run-ios this time the app opens with the local development server, if I terminate the development server then I will be getting Unhandled JS Exception error. 所以我这次使用本地开发服务器打开应用程序时使用react-native run-ios ,如果我终止开发服务器,那么我将收到Unhandled JS Exception错误。 For Android I tried the following steps to make it work. 对于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

Even if I terminate the local development server the app will work in Android. 即使我终止本地开发服务器,该应用程序也可以在Android中运行。 Any help for building offline bundle for iOS is appreciated. 任何有关为iOS构建离线捆绑包的帮助都表示赞赏。

Edit 1: 编辑1:

After bundling for iOS using the command 使用该命令捆绑iOS之后

react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

I'm able to generate main.jsbundle inside iOS directory and then followed the following steps. 我能够在iOS目录中生成main.jsbundle ,然后按照以下步骤操作。

  1. Removed all the App Transport Security Settings and added Allow Arbitrary Loads(true) inside Info.plist file. 删除了所有App Transport Security Settings并在Info.plist文件中添加了Allow Arbitrary Loads(true)

  2. Edited the Run Edit Scheme to Release 编辑了Run Edit Scheme to Release

  3. Changed the jsCodeLocation from 更改了jsCodeLocation

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

to

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  1. Product -> Build 产品 - > 构建

After following the above steps I'm getting the following error 执行上述步骤后,我收到以下错误

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

Here is the screenshot of the whole error 这是整个错误的屏幕截图 在此输入图像描述

Here is the project structure 这是项目结构

在此输入图像描述

Current Version : 当前版本

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

It appears that the build script that runs the bundler command does not handle whitespace characters in file paths correctly. 似乎运行bundler命令的构建脚本无法正确处理文件路径中的空白字符。 I can see from the screenshot you posted that the path to your project contains a space character in the React-Native Projects directory. 我可以从您发布的屏幕截图中看到,项目的路径在React-Native Projects目录中包含一个空格字符。

If you rename the directory to eg React-Native-Projects , the Archive build will work correctly. 如果将目录重命名为例如React-Native-Projects ,则归档构建将正常工作。

In general, it's a good developer practice to limit directory and file names to alphanumeric characters, because many Unix tools require escaping other character types. 通常,将目录和文件名限制为字母数字字符是一种很好的开发人员惯例,因为许多Unix工具需要转义其他字符类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM