React-native-config: Can't Find GeneratedDotEnv.m Upon Build

Created on 2 Jun 2017  路  30Comments  路  Source: luggit/react-native-config

Facing a build error with the following error message on X-Code:

Lexical or Preprocessor Issue -> /MyApp/node_modules/react-native-config/ios/ReactNativeConfig/ReactNativeConfig.m:2:10: 'GeneratedDotEnv.m' file not found.

Ran react-native run-ios too and facing a similar error and I've also done the library linking process.

In the includes selection of X-Code's jump-bar navigation helper, the file is there but somehow I'm facing this import issue. I've attached the file here.

Not sure what I'm doing wrong. Would appreciate your help on this.

Thank you in advance.

screen shot 2017-06-03 at 1 02 29 am

Most helpful comment

@DLevai94 Here's what I ended up with:

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"\
                           " && export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig"\
                           " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

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

There's probably a more elegant way to do it, but it worked for me.

All 30 comments

+1

Did you add react-native-config through cocoapods? Cause that was the problem for me, GeneratedDotEnv.m is created during the build by a custom script build phase, which is not supported by cocoapods =/

@viniciusvgv, @HADB, @szharifs : How did you manage to rectify this error. If you can please elaborate on the steps you used.

@AmandeepSingh06 I had to install react-native-config through react-native link instead of adding it straight to the podfile

Has anyone found any solution? I'm stuck with this for 2 days now...
Steps:
npm i react-native-config
react-native link react-native config
then added and configured everything in Xcode

Ok, so after 3 days working on it, I found a workaround
add to your Podfile :

post_install do |installer|
      phase.shell_script = "cd ../../"\
                           " && RNC_ROOT=./node_modules/react-native-config/"\
                           " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
                           " && export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig"\
                           " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

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

and run from your project root:
pod install --project-directory=ios && react-native run-ios

My understanding is since react-native 0.50, CocoaPods projects are automatically linked and for some reason (maybe related to this issue) the ruby script was not executed

@gaultierq it doesn't work for me.

[!] An error occurred while processing the post-install hook of the Podfile.

undefined local variable or method `phase' for #<Pod::Podfile:0x007fcbd5bd7330>

/Users/davidlevai/Desktop/Learning/Freel/BES/besmobile/ios/Podfile:36:in `block (3 levels) in from_ruby'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-core-1.3.1/lib/cocoapods-core/podfile.rb:179:in `post_install!'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:619:in `run_podfile_post_install_hook'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:607:in `block in run_podfile_post_install_hooks'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/user_interface.rb:142:in `message'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:606:in `run_podfile_post_install_hooks'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:185:in `block in generate_pods_project'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/user_interface.rb:64:in `section'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:182:in `generate_pods_project'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:119:in `install!'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/command/install.rb:41:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/lib/cocoapods/command.rb:52:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/cocoapods-1.3.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'

try to add logs in the podfile script and ruby script and see what is going wrong

@DLevai94 Here's what I ended up with:

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"\
                           " && export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig"\
                           " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"

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

There's probably a more elegant way to do it, but it worked for me.

Thanks for your help. Now, I decided to downgrade RN to 0.49.5. On this version, it works without any hacks. :) I guess the problem is the new mechanics of react-native link from version 0.50.

@DLevai94 You can downgrade to RN 0.49 and link and then upgrade again to 0.51 馃

  1. Edit __ios/Podfile__
-   #pod 'react-native-config', :path => '../node_modules/react-native-config'
  1. Edit __package.json__
-    "react-native": "^0.51.0",
+    "react-native": "=0.49.3",
  1. Run commands
rm -rf node_modules
yarn install
./node_modules/.bin/react-native link react-native-config
  1. Edit __package.json__
-    "react-native": "=0.49.3",
+    "react-native": "^0.51.0",
  1. Run commands
rm -rf node_modules
yarn install

This is very much a work around waiting for an official fix. But it is better then staying on 0.49.

If you use fastlane try bundle exec fastlane comand

@DLevai94 @mikelovesrobots
Using:
react-native: 0.57.3 => 0.57.3

I had to set Info.plist prefix preprocessor file to $(SRCROOT)/../node_modules/react-native-config/ios/ReactNativeConfig/GeneratedInfoPlistDotEnv.h instead of ${BUILD_DIR}/GeneratedInfoPlistDotEnv.h because the adjusted invocation in the Podfile runs and outputs into the node_modules directory instead of Xcode derived assets BUILD_DIR.

But other than that adjustment, npm install + react-native link react-native-config + pod install + Info.plist adjustment works out.

There seem to be many different ways around this, for us the solution was:

  1. Remove all references to react-native-config from our Podfile & Podfile.lock
  2. Manually link the project (dragging the ReactNativeConfig.xcodeproj from your node_modules into Libraries, etc.)
  3. Running in project root folder yarn && cd ios && pod install.

This basically removed react-native-config from being handled by cocoapods, making the necessary file available on build again. Can't however guarantee this solution will work for everyone - just thought I'd share seen as this as well as the many other threads lead us to this conclusion.

Versions:

react-native: 0.57.7
react-native-config: 0.11.7
cocoapods: 1.5.3

I fixed this by changing the Info.plist prefix preprocessor file to ${CONFIGURATION_BUILD_DIR}/react-native-config/react_native_config.framework/Headers/GeneratedInfoPlistDotEnv.h

@breadadams you saved my days. Thanks a lot bro.

Using react-native 0.56.1 and @mikelovesrobots 's podfile routine fixed my build issue.

Add this script to scheme pre-actions:

Product - Scheme - Edit Scheme -> Unfold Build -> Pre-actions


RNC_ROOT=$(realpath $SRCROOT/../node_modules/react-native-config/)
export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig
export BUILD_DIR=$RNC_ROOT/ios/ReactNativeConfig
ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby

Maybe someone knows a way to automatically put it into the scheme

ios integration is supposed to be fixed by this pr: https://github.com/luggit/react-native-config/pull/349 no need to add any custom lines to prebuild step (except for those defined in readme) or Podfile

I've updated my project to 0.60 rn version and get the same issue. In 0.60 cocoapods integration and autolinking from the box, but it doesn't work. I've tried manual linking and it was unsuccessful. As I understood, building using cocoapods don't run BuildDotenvConfig.ruby which should create two files GeneratedDotEnv.m and GeneratedInfoPlistDotEnv.h. Does anyone have a solution?

@Boris-Vladimirovich

I am struggling to get 0.58 working and the above fixes aren't working for me.

@maxkomarychev Checked on master, this (unfortunately) doesn't fix the problem.

For other people, this package works great if you don't need to expose the ENV vars in iOS land. Simply don't add the package to the project or include the cocoa-pods

Same issue here, testing on RN 0.63, any updates?

I had to link the library again.

Selected my Target > Build Phases > Link Binary With Libraries
I added the "libReactNativeConfig.a" library to my libraries.
image

Cleaned and Build and it worked for me.

I can finally make it works with RN 0.60.4
the solution is here
https://github.com/luggit/react-native-config/issues/357#issuecomment-508649128

@mcanobbio are you using multiple environments?

so does this project support auto-linking for RN > 0.60?

same question with RN > 0.60

Was this page helpful?
0 / 5 - 0 ratings