React Native 收纳

React Native开发之iOS打包ipa发布(亲测可行)

2017-01-17  本文已影响1159人  ZPengs

欢迎大家加群讨论
点击链接加入群[ReactNative-解决问题交流群] :644124441
点击链接加入群[ReactNative技术交流群2] :687663534

我们可以用React Native提供的命令:
react-native bundle

Options:
--entry-file Path to the root JS file, either absolute or relative to JS root [required]
--platform Either "ios" or "android"
--transformer Specify a custom transformer to be used (absolute path) [default: "/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js"]
--dev If false, warnings are disabled and the bundle is minified [default: true]
--prepack If true, the output bundle will use the Prepack format. [default: false]
--bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json
--bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]
--bundle-encoding Encoding the bundle should be written in ([https://nodejs.org/api/buffer.html#buffer_buffer).](https://nodejs.org/api/buffer.html#buffer_buffer).) [default: "utf8"]
--sourcemap-output File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map
--assets-dest Directory name where to store assets referenced in the bundle
--verbose Enables logging [default: false]

其实用Xcode打开后可以开到main.js文件,不过是红色状态的,因为引用了但是并没有这个文件存在,React Native这样做的目的可能就是提示你还没有生成离线数据的意思吧。  所以我们这里的bundle-output就选择这个main.js,如果你想用别的名字,理论上是可以的,但是会提示找不到这个文件,你需要先生成一个空的文件就可以了。  --assets-dest选择./ios就可以了,因为它会帮你在./ios下生成assets文件夹。

第一步

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

如果你是4.9版本以上使用一下命令:

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

准备就绪,开始打包。打包完后你就会看到main.js文件变为已有状态了。  然后打开Appdelegate.m文件,修改:

Paste_Image.png
//jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; 

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

然后再把assets文件夹添加到工程中,注意的是必须选择Creat folder references否则运行时将会报错,无法找到文件。


assets文件夹

第二步运行环境下的编译设置(Debug/Release)

image.png

最后command+R运行,发现:程序崩溃了

出现这样的原因是因为Build Phases中Copy Bundle Resources没有添加我们刚才生成的main.js。

Copy Bundle Resources
再次command+R运行,跑起来了。
之后正常走Xcode打包发布流程就好了。
如果按照我这个步骤来还是不成功,给个❤️,私信我帮你!☺

遇到错误1:

如果你打包IPA 安装到真机上时遇到这个错误

dyld: Library not loaded: @rpath/RSKImageCropper.framework/RSKImageCropper
  Referenced from: /var/containers/Bundle/Application/04722779-7AB0-40C4-961E-4EED77C876A1/RichMedia1.app/RichMedia1
  Reason: image not found
image.png

在项目的General->Embedded Binaries中,将我们自定的framework 添加进去,如下图:

image.png

错误二:

can't link with a main executable file for architecture armv7
解决:

在 target 下有个 test 工程,
找到 General,然后会看到一个 testing 
在 testing 下有个
 Allow testing Host Application APIs ,它默认是勾上的,把勾去掉,

相关文章:
1.React Native开发错误警告处理总结(已解决 !持续更新)
2.ReactNative 实现的文件上传功能(实测可行!)
3.React Native开发总结之:开发技巧和调试技巧
4.React Native开发总结:一、开发环境配置
5.ReactNative之Android打包APK方法(趟坑过程)
6Android 调试错误总结(ReactNative开发)(持续更新)
7.ReactNative开发之真机测试
8React Native开发之iOS打包ipa发布(亲测可行)

上一篇下一篇

猜你喜欢

热点阅读