React-native-config: Not working with RN 0.60.4

Created on 23 Jul 2019  Â·  49Comments  Â·  Source: luggit/react-native-config

The library is not working with RN 0.60.4, automatic linking is not working. If I try to link manually, it throws errors. On pod install it produces error 'GeneratedDotEnv.m' file not found.

Any help? 🆘

Most helpful comment

@Elvinra that worked for me!!

Another fix, if you install with npmjs, then
yarn add react-native-config
Open podfile and add

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

cd iOS && pod install

All 49 comments

You are using react-native-config from npmjs, try to use this librairy directly from github
yarn add https://github.com/luggit/react-native-config

I ended up using this specific commit and then I didn't need the post-install scripts mentioned in other issues
github.com/luggit/react-native-config.git#89a602b

@Elvinra that worked for me!!

Another fix, if you install with npmjs, then
yarn add react-native-config
Open podfile and add

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

cd iOS && pod install

@Elvinra we can also work but clean and rebulding issues causes back again
Please check that node_modules/react-native-config/ios/ReactNativeConfig contains same up to date files from repo.

Nevermind, just found out that this repo is updated but not published to npm.
Replace "react-native-toasty": "current version" with "react-native-config": "git+https://github.com/luggit/react-native-config.git"

Then you can run pod install without issue.

Still I don't understand why the npm version is not updated anymore.

I need help! I've try @dineshmm23's solution but I'm still getting this error:

ruby: No such file or directory -- ./node_modules/react-native-config//ios/ReactNativeConfig/BuildDotenvConfig.ruby (LoadError)

Command PhaseScriptExecution failed with a nonzero exit code

@fariasmark Are you missing the script? What version of react-native-config and react-native are you using?

The error that you reported is not the same as the original issue so you may want to open your own issue

@fariasmark just follow these steps:

yarn add react-native-config

then go to ios>Podfile and add below code at the bottom of file.

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

then run pod install

now run react-native run-ios

@fariasmark Try replacing BuildDotenvConfig.ruby with BuildDotenvConfig.rb. It helped in my case.

Here is the guide for some poor soul javascript dev like me out there:

  1. yarn add luggit/react-native-config#master (don't use the version on npm or you will spend way too much time to figure out how this work)
    Note: if you want to anchor your version then use this commit instead of master https://github.com/luggit/react-native-config/commit/1eb6ac01991210ddad2989857359a0f6ee35d734
  2. Follow exactly like the README, you don't need to add any code inside your Podfile
    After pod install there will be some warning like this [!] react-native-config has added 1 script phase. (which mean you are doing this right)
    2a. If your want to support Info.plist, replace __RN_CONFIG_xxx to $(xxx) inside your Info.plist file
  3. Build and run your project like normal

On the side note, the README should be restructure for it is very confusing

@s123121 I've done everything that you said. What does your Pre-actions script look like inside of schemes > Build > Pre-actions ? Mine looks like:

echo ".env.testing" > /tmp/envfile
${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"

Not sure if i'm following the instruction correctly for when I want my configs in info.plist

I'm also having some trouble with getting RN0.60.4 to work with this library. I get an error in the preprocessing Info.plist

GeneratedInfoPlistDotEnv.h' file not found

It seems like there's so many different fixes each for different versions and if people have multiple envs.

Can we get some way of version controlling each solution and have an updated example. (it's currently at RN50). Perhaps just having a proper example for each version will alleviate all the issues popping up because this library doesn't work with this version.

@s123121 thank you alot

@ninjz you are correct remember that choose your target for Provide build settings form
Screen Shot 2019-07-30 at 1 41 46 PM

@rexhuynh Thanks so much that seemed to solve my issue

@rexhuynh you save my day

@Elvinra that worked for me!!

Another fix, if you install with npmjs, then
yarn add react-native-config
Open podfile and add

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

cd iOS && pod install

Thanks. It works

What I'm doing for RN 0.60.4 (Upgraded from 0.59.9) is basically

  1. Change react-native-config ver to master "react-native-config": "github:luggit/react-native-config#master" or lock commit to 1eb6ac0 as @s123121 said. Then npm install it
  2. (if exists) Remove pod 'react-native-config', :path => '../node_modules/react-native-config' in Podfile
  3. (if exists) Remove the package link at Link Binary with libraries in your XCode Workspace
  4. Add the following to Podfile, notice that it's .rb instead of .ruby for me (Thanks @mchudy)
post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end
  1. run pod install at ios folder

But I'm getting this now, anyone knows why?

/Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `join': no implicit conversion of nil into String (TypeError)
    from /Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `read_dot_env'
    from ./node_modules/react-native-config//ios/ReactNativeConfig/BuildDotenvConfig.rb:15:in `<main>'
reading env file from  and writing .m to 
going to read env file from root folder 
Command PhaseScriptExecution failed with a nonzero exit code

@kdenz if remove script from Podfile it tun with react-native run-ios, but when try to archive - it fails with
BuildProductsPath/GeneratedInfoPlistDotEnv.h' file not found

@Mlobaievskyi That's so wierd lol
I'm still trying to figure out this error

/Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `join': no implicit conversion of nil into String (TypeError)
    from /Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `read_dot_env'
    from ./node_modules/react-native-config//ios/ReactNativeConfig/BuildDotenvConfig.rb:15:in `<main>'
reading env file from  and writing .m to 
going to read env file from root folder 
Command PhaseScriptExecution failed with a nonzero exit code

Found solution

1) yarn add react-native-config
2) manually link https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking
3) add next to react-native.config.js

module.exports = {
  dependencies: {
    'react-native-config': {
      platforms: {
        ios: null
      }
    }
  }
}

4) react-native run-ios (archive also work)

Can't seem to get this running either. Followed various options from above and none have worked. Got the same error as @kdenz when I tried his one.

I'll see if I can get it going with a react-native init and see if I can figure out what's going on from there.

This behavior seems to be extremely inconsistent. Everything was working fine for me. Then I deleted the build folder, tried to build again, and this error came back. Then I unlinked the library
react-native unlink react-native-config which deleted this line
pod 'react-native-config', :path => '../node_modules/react-native-config' from Podfile.

And everything stated working again. Podfile does have the solution provided by @ravimaurya-nickelfox .

What worked for me now on 0.60.4, inspired by @Mlobaievskyi and @s123121 -

  1. Change react-native-config ver to master "react-native-config": "github:luggit/react-native-config#master" or lock commit to 1eb6ac0 as @s123121 said. Then npm install it
  2. Follow the steps here to manually link the package https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking

  3. And then put the following into react-native.config.js at root folder (Not sure if necessary)
module.exports = {
  dependencies: {
    'react-native-config': {
      platforms: {
        ios: null
      }
    }
  }
}
  1. Remember to remove this snippet from Podfile
post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

and the line pod 'react-native-config', :path => '../node_modules/react-native-config'
then run pod install again (To be safe you can delete Podfile.lock first)

Then I was getting 'GeneratedDotEnv.m' file not found. error
After battling it a while I realized from this PR (https://github.com/luggit/react-native-config/commit/1eb6ac01991210ddad2989857359a0f6ee35d734) that I should remove all these preprocess settings. After that 'GeneratedDotEnv.m' file not found. error is gone and it works for me.
image

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

THIS WORKS!!!!!!!!!!!!

Do not trust the latest README.
If you want to use info.plist and Js,

  1. Follow this document.
  2. Put the following code in your podfile
  3. Everything will work!!!!
post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
      phase.shell_script = "cd ../../"\
       " && RNC_ROOT=./node_modules/react-native-config/"\
       " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\> 
      " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

      target.build_phases << phase
      target.build_phases.move(phase,0)
    end
  end
 end

You are using react-native-config from npmjs, try to use this librairy directly from github
yarn add https://github.com/luggit/react-native-config

This has worked for me correctly

Can we have a new release from master? I don't feel comfortable hardcoding a repository link in my package.json.

Chiming in here because this issue was invaluable in helping me to upgrade to 0.60.5 (and at this point I have this working in plist and in javascript):

If you remove preprocessor settings, don't expect any variables in your plist file to work. I did this because I simply needed my app to build so I could move onto other dependencies.

If you want to use variables in your plist and need to remove the preprocessor steps to get your app to run, make sure to follow @s123121's steps above.

NOTE: the readme is different from comments here that I've gotten to work, specifically the line: ${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"

The README has the first operation in quotes which wasn't getting there for me, when I used the one posted by @ninjz this finally worked.

I second what @BrendanJMurray has offered.

What worked for me now on 0.60.4, inspired by @Mlobaievskyi and @s123121 -

  1. Change react-native-config ver to master "react-native-config": "github:luggit/react-native-config#master" or lock commit to 1eb6ac0 as @s123121 said. Then npm install it
  2. Follow the steps here to manually link the package https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking

  3. And then put the following into react-native.config.js at root folder (Not sure if necessary)
module.exports = {
  dependencies: {
    'react-native-config': {
      platforms: {
        ios: null
      }
    }
  }
}
  1. Remember to remove this snippet from Podfile
post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

and the line pod 'react-native-config', :path => '../node_modules/react-native-config'
then run pod install again (To be safe you can delete Podfile.lock first)

Then I was getting 'GeneratedDotEnv.m' file not found. error
After battling it a while I realized from this PR (1eb6ac0) that I should remove all these preprocess settings. After that 'GeneratedDotEnv.m' file not found. error is gone and it works for me.
image

There's got to be another solution that doesn't involve manual linking. It's a massive job when you have a lot of dependencies, and is more prone to human error. 😕

I've changed the below configs in "Build Settings" of project

  1. Info.plist Other Preprocessor Flags => -traditional
  2. Info.plist Preprocessor Prefix File => ${BUILD_DIR}/GeneratedInfoPlistDotEnv.h
  3. Preprocess Info.plist File => Yes

and it worked

@mehdihz npm version?

   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end

@ravimaurya-nickelfox You're the best ! :D

@mehdihz npm version?

Sorry for late answer. My npm version: 6.9.0

I was beating my head at this for the better part of a day. Everything worked fine with little to no intervention on react 0.57 for me, moving to 0.60+ was a ball!

In any case what I needed was the following:

  1. Store variables in the binary (e.g. URL and pinned public keys) and access them in JS (Config.X)
  2. Pass variables to Info.plist (picked up by some sdks such as FB) $(MYVAR)
  3. Pass variables through the bundler (bundle version info and other vars) ENVFILE=.env.x react-native run-ios

react-native-config did 1 and 2 for me, but for 3, I needed to use react-native-dotenv.

Now my issue could be that these both read/write to /tmp/envfile but in essence this should not be an issue because you basically only want one .env.XYZ file to be consumed on any one build.

For 1, I needed only to import the Config variable and use as needed. Between builds I need to rebuild since this is passed through the binary.

For 2, I needed to do some acrobatics and to stand on my head a bit. Basically the documentation seems to have changed and you no longer should be using the prefix __RN_CONFIG_VARNAME but instead $(VARNAME) only.

Here also you need to make sure that your xcconfig file references the tmp.xcconfig file which should be generated by an early build phase step that you have to create

${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig

When I ran this command in terminal alone I noticed that it generated an empty tmp.xcconfig which was simply because I had not created a /tmp/envfile. Now my scheme build pre-action does this:

export ENVFILE=.env.test
echo $ENVFILE > /tmp/envfile   
echo $ENVFILE > /tmp/dotenv

So it's not that the build doesn't have a /tmp/envfile to work with...at this point I figured it must have been deleted somewhere in the series of scripts running.

Reviewing the build logs when I had issues with vars not making it into the package, I noticed a subtle message:


* Missing .env file **


In the same log I noted that a previous run of BuildXCConfig.rb had no issues. Reviewing BuildXCConfig I realized that the last step deletes the /tmp/envfile...which of course was the crux of the problem, at least for my specific issue, I've create a pull request here for this: https://github.com/luggit/react-native-config/pull/404

The additional step needed for 2 to work properly is to make sure that your Project->Info->Configurations configured file (for me Pods-Project-Prod.xcconfig) calls

#include? "tmp.xcconfig"

at the top.

Note this gets stamped any time you do a _pod install_ so we'd need a post_install step to put it back in.

For 3 I still can't find a very clean way of doing this for xcode. At present you need the scheme build pre-action to create the /tmp/dotenv file, but to pass ENVFILE to the bundler, I basically had to modify the node_modules/react-native/scripts/node-binary.sh and add the export there:

export ENVFILE=$(cat /tmp/dotenv)

In React < 0.60 I could add this bit to the React.xproj packager build phase, however with React > 0.60 the logic of the scripts have changed.

Edit

As per the note above here is a post install to configure the xcconfig file

post_install do |installer|
  installer.pods_project.targets.each do |target|
      if(target.name=='Pods-YOURPROJECTTARGET')
          puts "Updating #{target.name} for react-native-config configs to be included"
          target.build_configurations.each do |config|
              xcconfig_path = config.base_configuration_reference.real_path
              xcconfig = File.read(xcconfig_path)
              nativeconfig = '#include? "tmp.xcconfig"' + "\r\n" + xcconfig
              File.open(xcconfig_path, "w") { |file|  file << nativeconfig }
          end      
        end
  end
end

Edit 2

you can add the packager ENVFILE option to the node launch script using a post install in your package.json:

# package.json
scripts: {
...
"postinstall":"sh ./scripts/postinstall.sh"
...
}

and

grep -q ENVFILE ./node_modules/react-native/scripts/node-binary.sh
if [ $? -eq 0 ]
then
        echo node ENVFILE patch already applied
else
        echo "export ENVFILE=$(cat /tmp/dotenv)" >> ./node_modules/react-native/scripts/node-binary.sh
fi

exit 0

post_install do |installer|
installer.pods_project.targets.each do |target|
if(target.name=='Pods-YOURPROJECTTARGET')
puts "Updating #{target.name} for react-native-config configs to be included"
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
xcconfig = File.read(xcconfig_path)
nativeconfig = '#include? "tmp.xcconfig"' + "\rn" + xcconfig
File.open(xcconfig_path, "w") { |file| file << nativeconfig }
end
end
end
end

After running, it can be used by using acts-native run-ios, but after deleting ipa, the edit config is empty

_Clear xcode cache with_

shift + option + cmd + k

I just upgraded my React Native version to 0.61.4 and react-native-config ^0.12.0. @kdenz solution worked for me.

@Elvinra that worked for me!!

Another fix, if you install with npmjs, then
yarn add react-native-config
Open podfile and add

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

cd iOS && pod install

I had to replace that last line with:

" && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb \"${SRC_ROOT}/../\" \"${SYMROOT}\""

Thank you! @tmaly1980

FYI on RN 0.61.2:

In addition to https://github.com/luggit/react-native-config/issues/365#issuecomment-514487016 when using v0.11.7, v0.12.0 alleviates the need for this patch, after some additional small changes to your project

The library is not working with RN 0.60.4, automatic linking is not working. If I try to link manually, it throws errors. On pod install it produces error 'GeneratedDotEnv.m' file not found.

Any help? 🆘

For me, the problem was that ProjectTests target had the Preprocessor Prefix File set the same as the project, and it should be empty.

Otherwise, It worked only with the steps in the documentation.

react-native 0.60.5
react-native.config 0.12.0

Is there a solution without having to add code to Podfile ?
I also have this problem after upgrading react-native from 0.59.10 to 0.60.0

If you are using Pods just add (without react-native link react-native-config)

pod 'react-native-config', :path => '../node_modules/react-native-config/react-native-config.podspec'
in your Podfile

I got .env value in AppDelegate.m
but didn't get in info.plist.
NSDictionary *config = [ReactNativeConfig env];
NSLog(@"Configure: %@", config);

"react-native": "0.61.5"
"react-native-config": "luggit/react-native-config#master",

can anyone help me. (Please share steps)

Thanks

I was getting the "ld: library not found for -lReactNativeConfig" error after switching over to CocoaPods. I removed ReactNativeConfig from the Libraries folder, but forgot to clean up "Link Binary with Libraries" under Build Phases.

The error is the shell script is referencing a wrong path with the wrong filename

I had to edit 2 files:

  1. Podfile:
    " && RNC_ROOT=./node_modules/react-native-config/"\ to without '/' at the end =>
    " && RNC_ROOT=./node_modules/react-native-config"\ since if you will take closer look, the error is saying that path:
    /node_modules/react-native-config//ios/ReactNativeConfig wasn’t found.

  2. project.pbxproj:
    in this file i had to make sure i am referecing an exiting file, the file changes over the lib versions, so:
    shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb\" \"${SRCROOT}/..\" \"${SRCROOT}/release.xcconfig\"\n";
    to
    shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.ruby\" \"${SRCROOT}/..\" \"${SRCROOT}/release.xcconfig\"\n";

I'm using react-native-config 1.4.1 and was running into the empty object problem on ios so I added a new run script within Build Phases and got the config correctly populated as expected:

Update:

cd "$SRCROOT/../"
RNC_ROOT_DIR=$(pwd)
cd -

echo "Setting env for configuration: ${CONFIGURATION} with root dir: ${RNC_ROOT_DIR}"

if [ "${CONFIGURATION}" = "Release" ]; then
    echo "$RNC_ROOT_DIR/.env.production" > /tmp/envfile
    "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb" "$RNC_ROOT_DIR/.env.production" "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig"
else
    echo "$RNC_ROOT_DIR/.env.development" > /tmp/envfile
    "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb" "$RNC_ROOT_DIR/.env.development" "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig"
fi

Create a new run script and paste the above in there. Update your .env files within the script above accordingly. I'm using .env.production and .env.development for release and debug builds respectively.

Screen Shot 2020-12-07 at 11 45 07 PM

In order to change between debug and release builds you can go to "Edit schemes" for your target:

Screen Shot 2020-12-07 at 11 33 20 PM copy

And select between the 2 builds:

Screen Shot 2020-12-07 at 11 33 53 PM

The next build and run of your app should contain the contents between your various env files.

Was this page helpful?
0 / 5 - 0 ratings