您好,我正在尝试使用以下代码为 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
即使我终止本地开发服务器,该应用程序也可以在 Android 中运行。任何有关构建 iOS 离线捆绑包的帮助都将受到赞赏。
Edit 1:
使用命令捆绑 iOS 后
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios
我能够生成main.jsbundle进入 iOS 目录,然后按照以下步骤操作。
删除了所有App Transport Security Settings
并添加了Allow Arbitrary Loads(true)
inside 信息表 file.
编辑了运行编辑方案 to Release
-
改变了js代码位置 from
jsCodeLocation = [[RCTBundleURLProvider共享设置] jsBundleURLForBundleRoot:@“index”fallbackResource:nil];
to
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
-
Product -> Build
按照上述步骤后,我收到以下错误
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
这是项目结构
当前版本:
- 反应:16.0.0
- 反应本机:0.51.0
- 代码:9.2
运行捆绑程序命令的构建脚本似乎无法正确处理文件路径中的空格字符。从您发布的屏幕截图中我可以看到您的项目的路径在React-Native Projects
目录。
如果您将目录重命名为例如React-Native-Projects
,存档构建将正常工作。
一般来说,将目录和文件名限制为字母数字字符是一个很好的开发人员实践,因为许多 Unix 工具需要转义其他字符类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)