Open rawatnaresh opened 3 years ago
One thing @rawatnaresh , you do need use pre-actions since you use Podfile configuration. However I have the same problem, the configuration in Podfile somehow doesn't work.
react-native: 0.66.1 react-native-config: 1.4.5
@ibnukipa so there is no other option other than using it like this in pre-actions
cp "${PROJECT_DIR}/../.env.staging" "${PROJECT_DIR}/../.env" # replace .env.staging for your file
@luancurti sorry to bother you but do you have any suggestion on how can i make this work.
Did you guys find any way to make it work? @rawatnaresh @ibnukipa
@StanSarr Either you can add this in build phases
if [ "${CONFIGURATION}" == "Release" ]
then
echo ".env.production" > /tmp/envfile
else
echo ".env.staging" > /tmp/envfile
fi
OR paste this into Schema->Edit Schema->Pre-built actions
echo ".env.staging" > /tmp/envfile
echo ".env.staging" > /tmp/envfile
thanks, it's work
I've got it to work by using
ENVFILES = {
'Debug' => '$(PODS_ROOT)/../../../.env.development',
'Release' => '$(PODS_ROOT)/../../../.env.production',
}
instead of
ENVFILES = {
'Debug' => '$(PODS_ROOT)/../../.env.development',
'Release' => '$(PODS_ROOT)/../../.env.production',
}
Don't know why it works though. I would think PODS_ROOT
is ios/Pods/
so going two directory levels up would suffice, but apparently that's not the case.
Hi, I am facing similar issues, was wondering how to go about confirming that the env vars have been written/added to the build? @sanderdewilde @herarya was wondering if you had any ideas please, or anyone else in this thread please, thank you
@richlewis14
Hi! Did you try rm -rf ios/Pods
?
I also can not apply multiple env files for project.
It seems like not reflected Podfile. So I just remove Pods file, npx pod-install && yarn ios
, and it works!
Pre-action script that works for me
if [ "${CONFIGURATION}" = "Debug" ]; then
echo ".env.development" > /tmp/envfile
elif [ "${CONFIGURATION}" = "Staging" ]; then
echo ".env.staging" > /tmp/envfile
elif [ "${CONFIGURATION}" = "Release" ]; then
echo ".env.production" > /tmp/envfile
fi
"${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb" "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"
The postinstall script in Podfile adds build setting named ENVFILE
to react-native-config
target, but BuildXCConfig.rb
and ReadDotEnv.rb
scripts don't read build settings at all, let alone the build settings in react-native-config
target.
Since ReadDotEnv.rb
always picks /tmp/envfile
first, let pre-action prepare right value of /tmp/envfile
for BuildXCConfig.rb
to consume. Then this postinstall script in Podfile can be removed.
As mentioned in the docs we can use following approach to use different env file for different build configurations
Based on that, this is how my
Podfile
looks likeI've
.env
and.env.prod
in the root dir of my project and I'm trying to use.env
for bothDebug
&Staging
and.env.prod
forRelease
Here I'm using
Release
configuration forRelease Schema
When i select the
Release
schema and run the app it is still reading values fro.env
file. Am i missing something here?