react-native-config: Availability in Build settings and Info.plist problem
where we must to add below code in step 6 of Availability in Build settings and Info.plist
section:
"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb" "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 33 (5 by maintainers)
Thanks for adding the patch to the latest release, but the plist variables on first build are still not working for me. Can someone post a working example on how to configure this correctly?
EDIT: I figured it out by myself
Necessary modification in
BuildDotenvConfig.rb
line 28 (Pull-Request https://github.com/luggit/react-native-config/pull/457) to re-enable the creation ofGeneratedInfoPlistDotEnv.h
which was lost in update 0.11.7 to 0.12.0.Add this 2 scripts to a
scripts
folder in project rootgenerate-dot-env-files.sh
:This script creates/updates necessary
GeneratedDotEnv.m
andGeneratedInfoPlistDotEnv.h
files.generate-env-config.sh
:This script generates
tmp.xcconfig
from.env
file which is used to access variables from JavaScript side.In Xcode select your main project file and add 2
External Build Tool Configurations
in theTargets
areaGenerateEnvFiles
:GenerateEnvConfigFiles
:Open your build scheme, disable option
Parallelize Build
and add both newly created targets before your app targets, placeGenerateEnvConfigFiles
on first,GenerateEnvFiles
at second position.In your build scheme select Build -> Pre-Actions, set
/bin/sh
as Shell and add following script:This logs the script output to
prebuild.log
file inios
folder. It removes the preprocessed info.plist so variable changes gets updated on every build.Open up the
Build Settings
of your app target, search forpreprocess
and add following:Finally you can use your variables defined in .env file (e.g. APP_VERSION and APP_BUILD) in your Info.plist with RNC_APP_VERSION and RNC_APP_BUILD and the variables are updated on every build.
Some further thoughts:
tmp.xcconfig
but this is out of my scopeReactNativeConfig
instead ofGenerateEnvFiles
target because the necessary files were generated on build (BuildDotenvConfig.rb
is called as run script) but it didn’t worked this time.This is my solution :
It was not very clear from README instructions where to add the script to generate
tmp.xcconfig
, so I mistakenly added it to the Build Phases under my application target. As it turned out it was too late:Info.plist
is copied to the BUILD_DIR as a first step of the build andtmp.xcconfig
is generated after that. As a result on the first build values from thetmp.xcconfig
are not picked up and changes to the.env
file are only picked up by the second build after the change is made.The correct place where to add
BuildXCConfig.rb
is in Edit scheme… -> Build -> Pre-actions. Also make sure to select your target for “Provide build settings from”.Otherwise the approach seems to work correctly and you don’t need to make loads of manual work as described in https://github.com/luggit/react-native-config/issues/391#issuecomment-632331803.
PS Note that variables don’t have
RNC_
prefix as with the legacy approach involving theInfo.plist
preprocessing.UPD
Apparently one needs to setup same Pre-Action for the Archive schema, so values are available during the Archive build. And likely for every single schema you use. So I decided to to run this script manually before invoking Xcode to avoid maintaining same code in multiple places.
Hi ! If your issue is
Build input file cannot be found: GeneratedDotEnv.m
and if you are using pods and RN > 0.60, you can patch the podspec with this commit : https://github.com/bamlab/react-native-config/commit/05761868680ad46c9dbd1f56d7d504f056f444db(file located at
node_modules/react-native-config/react-native-config.podspec
)Explanation: The custom pod script generates the
GeneratedDotEnv.m
file at the same time XCode requires it. There is a race condition. In order to fix that, we need to tell XCode that our script outputs one file that is required in another step. Doing so, XCode new Build system will create a correct dependency graph and erase this race condition.Source: http://www.gietal.net/blog/xcode10-and-prebuild-script-output-files-xcfilelist
If anyone needs https://github.com/luggit/react-native-config/issues/391#issuecomment-571948199 as a permanent patch:
patch-package
topostinstall
step inpackage.json
In our script we also need react-native-inhibit-warnings and jetifier
patches/react-native-config+1.0.0.patch
(Note I removed whitespace changes from @tpucci 's patch) 4.
yarn
ornpm install
5.cd ios && pod install --repo-update && cd -
Confirmed working on:
react-native
:0.61.5
react-native-config
:1.0.0
Ty bro! That was my issue
Since the update from 0.11.7 to 0.12.0 all variables used in info.plist are only updated on the second build. The Build log shows RN-config updates the variables correct on first build, but the info.plist in the produced app is not updated correspondingly.
This was better in v0.11.7 when plist-preprocessing was possible using the
GeneratedInfoPlistDotEnv.h
file. As this file is not longer produced after the update (due to changes inBuildDotenvConfig.ruby
nowBuildDotenvConfig.rb
) this convenient way of updating variables on first build is no longer available.Any thoughs on this?
leaving here a note in case someone else has the same issue I was still having an issue with Info.plist not being processed correctly when building in bitrise I have pre-action defined in both “build” and “archive”, and I can see that the file
tmp.xcconfig
exists but I guess there is some race condition after all.Running manually after
npm install
before the build step solves the issueI was having the same issue but I found that my bash script was not properly written in the prebuild scripts. It should be like
also, you have to write in the input
shell -> /bin/sh
and inProvide build settings from -> "your target"
I’m using pod generated xcconfig files, so I created a post_install that appends #include? “tmp.xcconfig”
Worked for me.
@tpucci Thanks for your suggestion (https://github.com/luggit/react-native-config/issues/391#issuecomment-571948199), it’s the only thing which seems to work for me, only issue is remembering to edit the podspec if/when node_modules is rebuilt 😩
@export-mike I’m using Bitrise as my CI/CD platform, and your custom script worked for me, thank you. I hope a proper fix is released soon.
Yeah so on my circle ci build, I’m now running this custom script which is a temporary measure.
patches in the .env file into info.plist