react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Project Config] Development / Release / Other?

Open bleonard opened this issue 11 years ago • 14 comments

For a variety of reasons, I'm trying to make additional configs in XCode. For example one is local against a local server and the other is against a staging server (or other configs).

I am having trouble getting these both to be able to be in debug mode (Command + R etc). In fact the only way to get Debug mode is to call my config the string "Debug" - I believe this is because that is the name of the one in the React xcode project.

I tried setting a variety of variables like RCT_DEBUG, RCT_DEV, and other ones from that config, but it did not work and I'm worried I'm going to miss something.

The same thing would be true for "Release" - I'd prefer to have a "staging" one and a"production" one and then I'd be really worried I'd be missing the right stuff for a real release.

In the end, I really just need to be able to build the project in a repeatable way (not changing the code) that can set a simple string as the "environment" as well as have control over the release / debug features of React.

This use case must be fairly common. Is there a better way to handle it or an example of a way to reliably control subproject dependencies?

bleonard avatar Aug 06 '15 16:08 bleonard

this is a first step: https://github.com/facebook/react-native/pull/2101 but I think having multiple "target" would be great

gre avatar Aug 06 '15 16:08 gre

I found that I could pass environment variables in the "Run" section of "Edit Scheme" Then I'm using this to allow a "staging" env even though I'm in running the "debug" config.

  NSDictionary *passed = [[NSProcessInfo processInfo] environment];
  NSString *override = [passed valueForKey:@"OVERRIDE_ENV"];
  if (override) {
    envName = override;
  }

bleonard avatar Aug 09 '15 04:08 bleonard

This issue hasn't come up for a lot of people yet it seems - if you would like to try your hand at submitting a pull request to add it to the core we can move the discussion there :) Otherwise let's archive this and bring it back if others find themselves with the same requirement where the change you kindly shared above isn't enough :)

brentvatne avatar Aug 09 '15 17:08 brentvatne

OK. That's fine now that I have a workaround. How is facebook handling different configs or are there really only two? "Move fast and staging === production" ? :) or is there no local server? or maybe you do it all on the command line. I found I could pass extra stuff through xcodebuild

bleonard avatar Aug 09 '15 18:08 bleonard

I hit this when creating new targets. The names don't match to Debug or Release so despite setting RCT_DEBUG it does not get used.

john-griffin avatar Aug 10 '15 22:08 john-griffin

Hmm, it seems my workaround only works only on launch from Xcode. If you load it onto the phone, it doesn't send that flag on relaunch. More or less back to square one on this one, then.

bleonard avatar Aug 12 '15 22:08 bleonard

We have the exact same scenario. And the workaround detailed is not really a solution either. I believe that building multiple apps with slight differences from the same codebase will be a quite common scenario? @brentvatne I suggest re-opening this issue. The problem is that calling the configuration "Debug" is the only way to get the dev tools working now.

pewallin avatar Sep 04 '15 12:09 pewallin

Yes there should be better control over this stuff and config files by default. How do i pass targets/build settings to JS effectively?

aphillipo avatar Oct 05 '15 22:10 aphillipo

I wrote up this blog post on the approaches we are taking with this issue: http://tech.taskrabbit.com/blog/2015/10/18/building-react-native-apps/

Hope it's helpful to someone that lands here.

bleonard avatar Oct 19 '15 05:10 bleonard

+1 for multiple targets, allowing per-environment configurations. Right now builds fail with anything other than DEBUG and RELEASE targets.

jmreidy avatar Nov 19 '15 22:11 jmreidy

I'm targeting an Android release rather than iOS, but it'd be useful to have config variables to point the 'debug' APK at my staging API server rather than my production one.

Currently the best way to do this seems to be editing the debug gradle build in build.gradle, however assuming we release this to iOS clients as well it would be nice to have a unified place to define such environment variables.

Zensaburou avatar Feb 24 '16 18:02 Zensaburou

Some people here might find it useful to know that there is a global.__DEV__ variable exposed to the Javascript bundle which can be true or false. It is dependent on a parameter you pass to the JS bundle URL: Either &dev=true or &dev=false.

Of course this is neither documented nor official, so your apps might break if you use this and it gets changed in a future release. Be careful.

JonnyBurger avatar Mar 05 '16 16:03 JonnyBurger

Check out my Stack Overflow answer. If you are using custom configurations beyond the standard Debug and Release ones, such as Staging, and you're using Cocoapods, you need to specify in the Podfile that the Staging configuration is a debug configuration, not a release configuration. If unspecified, Cocoapods assumes other configurations are release configurations.

At the top of your Podfile add this line: xcodeproj 'MyProject', 'Staging' => :debug

If you're using Cocoapods 1.0, replace xcodeproj with project.

To actually update the settings:

rm -rf Pods/ pod install

Now your Staging configuration will behave like the Debug configuration as the DEBUG=1 preprocessor macro will be set on the Pods project (which is what RCT_DEV is based off of).

It would be nice if a note about this could be put in the React Native documentation as it is common for iOS devs to have more configurations than just Debug and Release.

jeffbowen avatar May 05 '16 15:05 jeffbowen

If you want to add new Staging configuration you can add line: "$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)", in LIBRARY_SEARCH_PATHS for your new configuration in project.pbxproj file

Just to remember - sometimes need to close and open XCode to see this changes.

And build will be successful!

That happens because build command put libraries into /Build/Products/Release-iphonesimulator/ folder And for your new configuration it searches libs into /Build/Products/Staging-iphonesimulator/ folder So can't find them and we need to declare library search path manually to point to release folder.

philipshurpik avatar Aug 13 '16 06:08 philipshurpik