您好,我正在尝试使用以下代码创建React Native 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
,这时应用程序将在本地开发服务器上打开,如果我终止开发服务器,则会出现未处理的JS异常错误。对于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
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios
I能够在iOS目录中生成main.jsbundle文件,并按照以下步骤操作:
- 删除所有的App Transport Security设置,并在Info.plist文件中添加Allow Arbitrary Loads(true)。
- 编辑Run Edit Scheme为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
这是整个错误的截图。
![enter image description here](https://istack.dev59.com/HaoEX.webp)
![enter image description here](https://istack.dev59.com/8qJtb.webp)
- React: 16.0.0 - React Native: 0.51.0 - Xcode:9.2
Cannot find module /users/jeffreyrajan/Projects/React-Native
。鉴于你的 JS 构建在开发模式下工作正常,这很可能是 Babel 或 Metro bundler 没有正确解析模块路径的问题。你是否使用了任何自定义的 Babel 插件或 Metro 转换器? - jevakallio