59

I come to React Native development without previous experience in iOS development. I want to build release. .ipa file - ideally from the command line but the official documentation Running On Device is very brief.

I was able to deploy applications on my iPhone manually via XCode but still, I can't find any "release IPA" file. I have updated my code with #ifdef DEBUG directives to make it more generic.

Is there a way to build an application in release mode only via the command-line? If no, what is "the official" way to generate an RN application?

I am currently using RN 0.20.

sodik
  • 4,675
  • 2
  • 29
  • 47
  • Possible duplicate of [How to build and deploy a react-native app from command line?](http://stackoverflow.com/questions/32885433/how-to-build-and-deploy-a-react-native-app-from-command-line) – Badal Shah Feb 18 '16 at 10:46
  • as I already mention I already use `#ifdef` trick. Unfortunatelly the other question does not mention how to build it (except that it was possible with `fastlane`). – sodik Feb 18 '16 at 14:13

3 Answers3

52

First, you need to create a bundle this way :

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

Then, you have to comment this line in AppDelegate.m :

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

and uncomment this one :

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

Then you have to go for Product -> Archive in Xcode and follow the steps based on your desired release

rohitanand
  • 710
  • 1
  • 4
  • 26
G. Hamaide
  • 7,078
  • 2
  • 36
  • 57
  • 2
    do you know where in the archive I can find .ipa file? – sodik Feb 18 '16 at 14:42
  • 1
    Once you archive, you can save your IPA file if I recall well. From the pop-up window that appears when your archive build succeeds. – G. Hamaide Feb 18 '16 at 14:50
  • in XCode 7.2.1 it just produced directory with several files but no IPA file. – sodik Feb 19 '16 at 07:11
  • Check [this](http://stackoverflow.com/questions/32573321/specify-location-for-ipa-file-in-xcode-7-ad-hoc-release) – G. Hamaide Feb 19 '16 at 07:27
  • 1. I have no IPA file on my computer (`find / -name "*.ipa" -print`) 2. Archive option has not further steps, it just create `.xcarchive` folder – sodik Feb 22 '16 at 10:50
  • 21
    To note, if Product > Archive is unavailable, make sure you have "Generic iOS Device" selected as your destination, and not one of the simulators. – Joshua Mar 08 '16 at 07:31
  • 3
    You need to be registered as an apple developer to create a `.ipa`, Then go to Product > Archive > Export... However, this answered my question as to how to actually create a production build, so thank you very much G. Hamaide – jakeforaker May 03 '16 at 02:22
  • How to do this on windows? There is no xcode on windows. – Mike Jan 28 '17 at 18:55
  • Should be "--platform ios" not "--platform iOS". "iOS" will result in error "Unrecognised platform" – Jian Yin Shen Feb 18 '17 at 01:48
  • 4
    I have only this string in AppDelegate.m: jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; What should I comment/uncomment? – valerybodak Mar 06 '17 at 14:58
  • I am run your command, it will say 'Assets destination folder is not set, skipping..' and I am not able to load image. – Nirmalsinh Rathod Feb 15 '18 at 08:43
  • @G.Hamaide Do you know how to do your approach using command line without opening XCode? – Tunvir Rahman Tusher Mar 13 '18 at 06:10
  • 2
    This answer is out of date - current versions of RN have a custom shell script in the xcode build process that automatically runs the bundling for you, so this is no longer necessary. – Jules Mar 29 '18 at 01:15
20

You have to set Scheme to Release.

From docs you have two ways.

To do this, go to Product → Scheme → Edit Scheme (cmd + <), make sure you're in the Run tab from the side, and set the Build Configuration dropdown to Release.

or

You can also use the React Native CLI to perform this operation using the option --configuration with the value Release (e.g. react-native run-ios --configuration Release).

Then you can generate your archive as usual.

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

Diego Mello
  • 5,220
  • 3
  • 17
  • 21
  • 4
    This is the correct updated answer, the others are old – jperelli May 17 '17 at 14:13
  • @jperelli this command is for running on simulator , it will launch a simulator, and the product is 'Release-iphonesimulator', not 'Release-iphoneos'. – Chris Yim Jul 10 '18 at 06:04
  • 2
    this is answer how to run, not how to build. everyone in react community seems to mistake these two things – luky Mar 25 '19 at 13:21
13

i cannot comment on the above answer, it is correct but you need to start with the following command in order for it to work:

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

the difference is 'ios' instead of 'iOS'

if not it will give the following error:

ProjectPath/node_modules/promise/lib/done.js:10
  throw err;
  ^
Hanane
  • 474
  • 6
  • 21