无法为 React Native (iOS) 创建离线包 [英] Cannot create offline bundle for react native (iOS)

查看:72
本文介绍了无法为 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-目标 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 目录中生成 ma​​in.jsbundle,然后按照以下步骤操作.

  1. 删除了所有应用传输安全设置并在Info.plist文件中添加了Allow Arbitrary Loads(true).>

  2. 运行编辑方案编辑为发布

  3. jsCodeLocation

    更改为

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

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

  1. 产品 -> 构建

执行上述步骤后,出现以下错误

文件/Users/jeffreyrajan/Library/Developer/Xcode/DerivedData/app_prod-fnewtufemaynsoedmhggmfjynoti/Build/Products/Release-iphonesimulator/app_prod.app/main.jsbundle 不存在.这一定是一个错误+ echo '反应原生

这是整个错误的截图

这里是项目结构

当前版本:

  • 反应:16.0.0
  • 反应原生:0.51.0
  • Xcode:9.2

解决方案

运行 bundler 命令的构建脚本似乎没有正确处理文件路径中的空白字符.我可以从您发布的屏幕截图中看到,您的项目路径在 React-Native Projects 目录中包含一个空格字符.

如果您将目录重命名为例如React-Native-Projects,存档构建将正常工作.

一般来说,将目录和文件名限制为字母数字字符是一个很好的开发人员做法,因为许多 Unix 工具需要转义其他字符类型.

Hi I was trying to create a offline bundle for react native iOS for testing using the following code

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. 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. For Android I tried the following steps to make it work.

  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. Any help for building offline bundle for iOS is appreciated.

Edit 1:

After bundling for iOS using the command

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.

  1. Removed all the App Transport Security Settings and added Allow Arbitrary Loads(true) inside Info.plist file.

  2. Edited the Run Edit Scheme to Release

  3. Changed the jsCodeLocation from

    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
  • React Native : 0.51.0
  • Xcode:9.2

解决方案

It appears that the build script that runs the bundler command does not handle whitespace characters in file paths correctly. I can see from the screenshot you posted that the path to your project contains a space character in the React-Native Projects directory.

If you rename the directory to e.g. React-Native-Projects, the Archive build will work correctly.

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.

这篇关于无法为 React Native (iOS) 创建离线包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆