Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Find GeneratedDotEnv.m Upon Build #125

Open
szharifs opened this issue Jun 2, 2017 · 30 comments
Open

Can't Find GeneratedDotEnv.m Upon Build #125

szharifs opened this issue Jun 2, 2017 · 30 comments

Comments

@szharifs
Copy link

szharifs commented Jun 2, 2017

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

@HADB
Copy link

HADB commented Sep 4, 2017

+1

@viniciusvgv
Copy link

viniciusvgv commented Oct 31, 2017

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 =/

@AmandeepSingh06
Copy link

AmandeepSingh06 commented Nov 17, 2017

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

@viniciusvgv
Copy link

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

@thedevdavid
Copy link

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

@gaultierq
Copy link

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

@thedevdavid
Copy link

thedevdavid commented Dec 4, 2017

@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>'

@gaultierq
Copy link

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

@mikelovesrobots
Copy link

mikelovesrobots commented Dec 7, 2017

@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.

@thedevdavid
Copy link

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.

@gabrielbull
Copy link

gabrielbull commented Dec 21, 2017

@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.

@eseQ
Copy link

eseQ commented Jul 9, 2018

If you use fastlane try bundle exec fastlane comand

@clarsen
Copy link

clarsen commented Nov 8, 2018

@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.

@breadadams
Copy link

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

@BerndSchrooten
Copy link

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

@skomarfaruque
Copy link

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

@devoNOTbevo
Copy link

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

@alvelig
Copy link

alvelig commented Apr 7, 2019

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

@maxkomarychev
Copy link
Contributor

ios integration is supposed to be fixed by this pr: #349 no need to add any custom lines to prebuild step (except for those defined in readme) or Podfile

@boris-92
Copy link

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?

@KevinColemanInc
Copy link

@Boris-Vladimirovich

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

@RWOverdijk
Copy link

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

@KevinColemanInc
Copy link

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

@mcousillas6
Copy link

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

@jorgeibarra01
Copy link

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.

@mcanobbio
Copy link

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

@KevinColemanInc
Copy link

Fixed @mcanobbio's link:

#357 (comment)

@hkung77
Copy link

hkung77 commented Jul 30, 2019

@mcanobbio are you using multiple environments?

@schumannd
Copy link
Contributor

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

@winseyli
Copy link

same question with RN > 0.60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests