2

I have a react-native app (iOS only for now) - and coming from a JS background and not being familiar with XCode, I am finding that documentation on creating production builds for iOS is very sparse. According to the one vague sentence on https://facebook.github.io/react-native/docs/running-on-device-ios.html :

The JS bundle will be built for dev or prod depending on your app's scheme (Debug = development build with warnings, Release = minified prod build with perf optimizations). To change the scheme navigate to Product > Scheme > Edit Scheme... in xcode and change Build Configuration between Debug and Release.

However, in XCode v7.3 this is what I see when I click Product > Scheme > Edit Scheme (no option to "change Build Configuration between Debug and Release") :

Product > Scheme > Edit Scheme

I understand how to run on the phone locally, and the difference between running on the simulator vs. phone. It works fine on the simulator and on plugged in phone.

Now when I archive the app, save for ad hoc distribution, upload to TestFairy, download on my phone, and run it - I often see things like the Yellowbox warning:

YellowBox

Also suspicious crashes like this (recorded by TestFairy):

Application Specific Information:
*** Terminating app due to uncaught exception 'RCTFatalException: Could not connect to development server.

Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate

URL: http://192.168.0.21:8081/index.ios.bundle?platform=ios', reason: 'Could not connect to development server.

Ensure the following:
- Node serv...'

Last Exception Backtrace:
0   CoreFoundation                      0x22939b8b __exceptionPreprocess (in CoreFoundation) + 127
1   libobjc.A.dylib                     0x220f6dff objc_exception_throw (in libobjc.A.dylib) + 39
2   CoreFoundation                      0x22939ad1 -[NSException initWithCoder:] (in CoreFoundation) + 1
3   myapp                            0x000b1ad5 0x98000 + 105173
4   myapp                            0x000cb01f 0x98000 + 208927
5   myapp                            0x000c9149 0x98000 + 201033
6   libdispatch.dylib                   0x224cbcbf _dispatch_call_block_and_release (in libdispatch.dylib) + 11
7   libdispatch.dylib                   0x224cbcab _dispatch_client_callout (in libdispatch.dylib) + 23
8   libdispatch.dylib                   0x224d0559 _dispatch_main_queue_callback_4CF (in libdispatch.dylib) + 1533
9   CoreFoundation                      0x228fb7d5 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ (in CoreFoundation) + 9
10  CoreFoundation                      0x228f9ccf __CFRunLoopRun (in CoreFoundation) + 1591
11  CoreFoundation                      0x22848289 CFRunLoopRunSpecific (in CoreFoundation) + 517
12  CoreFoundation                      0x2284807d CFRunLoopRunInMode (in CoreFoundation) + 109
13  GraphicsServices                    0x23e64af9 GSEventRunModal (in GraphicsServices) + 161
14  UIKit                               0x26f732c5 UIApplicationMain (in UIKit) + 145
15  myapp                            0x0009d4e7 0x98000 + 21735
16  libdyld.dylib                       0x224f4873 start (in libdyld.dylib) + 3

So, what are the proper steps to create a react native production build for distribution in XCode?

jakeforaker
  • 1,622
  • 1
  • 20
  • 34

2 Answers2

3

UPDATE

I found the upvoted answer to this question How to build .IPA for React Native? to solve the problem. I will leave this up since the question on that post is unrelated to my question, but it solves the issue of creating a production build, by using the command line:

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

And also uncommenting this line in AppDelegate.m:

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

Community
  • 1
  • 1
jakeforaker
  • 1,622
  • 1
  • 20
  • 34
0

FWIW, I ran into this problem with react-native 0.39.2.

To solve it:

1) add 'Objc -lc++' to 'Other Linker Flags' for the main project.

2) create the main.jsbundle with the terminal in the root of the react-native project (where index.ios.js lives): react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output iOS/main.jsbundle

3) In XCode open the Project, select the Project in the Navigator, then the apps target, then Build Phases, then Copy Bundle Resources, and add the main.jsbundle to the project so it's copied into the resulting app.

Then, the app would start on my iPad.

The documentation could have been a bit better on this point.

Hope this helps.

-Ken

Ken Corey
  • 435
  • 3
  • 15