如何为React Native构建.IPA?

时间:2016-02-18 08:31:22

标签: ios react-native

我在没有iOS开发经验的情况下来到React Native开发。我想构建发行版.IPA文件 - 最好是从命令行开始,但官方文档Running On Device非常简短。

我能够通过XCode手动在我的iPhone上部署应用程序,但我仍然找不到任何"发布IPA"文件。我使用#ifdef DEBUG指令更新了我的代码,使其更通用。

有没有办法只通过命令行在发布模式下构建应用程序?如果不是,那么"官员"生成RN应用程序的方法?

我目前正在使用RN 0.20。

4 个答案:

答案 0 :(得分:49)

首先,您需要以这种方式创建一个包:

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

然后,你必须在AppDelegate.m中注释这一行:

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

并取消注释:

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

然后你必须去产品 - >存档在Xcode中,并根据您所需的版本执行步骤

答案 1 :(得分:19)

您必须将Scheme设置为Release。

从文档中你有两种方式。

  

要执行此操作,请转到产品→方案→编辑方案(cmd +<),确保您位于旁边的“运行”选项卡中,并将“构建配置”下拉列表设置为“发布”。

  

您还可以使用React Native CLI使用选项 - 配置值Release(例如react-native run-ios --configuration Release)来执行此操作。

然后您可以照常生成档案。

https://facebook.github.io/react-native/docs/running-on-device.html#building-your-app-for-production

答案 2 :(得分:13)

我无法对上述答案发表评论, 它是正确的,但你需要从以下命令开始才能使它工作:

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

区别在于' ios'而不是iOS'

如果不是,则会出现以下错误:

ProjectPath/node_modules/promise/lib/done.js:10
  throw err;
  ^

答案 3 :(得分:0)

iOS

  1. 在根文件夹中使用以下简单命令使用Xcode打开iOS项目。

    xed ./ios
    
  2. 现在将以下命令粘贴到终端中

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

    enter image description here

  3. 像这样从Xcode编辑方案:

    产品->方案->编辑方案

    enter image description here

    编辑方案以发布

    enter image description here

现在,您有一个独立的Xcode项目,可以像本机Xcode项目一样进行构建/发布。

答案来自:https://medium.com/better-programming/create-ipa-and-apk-from-react-native-72fe53c6a8db

相关问题