Reputation: 147
I'm really struggling with what seems like a very primitive error. I have installed react-native-config and when console.logging the Config object it returns {}
.
The problem occurs both on android and iOS and it doesn't seem to be a linking issue because (even though RN 71.3 doesn't require manual linking) when following the steps to link manually on android I got an error saying RNCConfigPackage already linked.
This is a simplified version of my code:
import Config from 'react-native-config';
console.log(Config);
And this is what my .env file looks like:
REACT_APP_STAGE=development
TEST=ThisIsATest
ANOTHER_TEST=ThisIsAnotherTest
I have already tried:
ENVFILE=.env react-native run-android
to hard code the env fileI understand that this is very limited information in order to debug the issue but any direction and help is appreciated including any approach you would follow to debug.
EDIT: The Config appeared in the end but is very late to update, an issue more people seem to be facing, I have used react-native-dotenv instead.
Upvotes: 2
Views: 5374
Reputation: 1
For me using the following versions it worked on iOS after I ran pod install
inside ios
folder. For android all I had to do was the extra step that is mentioned in repo's readme.md: https://github.com/lugg/react-native-config?tab=readme-ov-file#extra-step-for-android
"react-native": "0.73.6",
"react-native-config": "^1.5.3",
Upvotes: 0
Reputation: 651
Here is a fix tested on
"react-native": "0.72.6"
"react-native-config": "^1.5.1"
Android
add to your app/build.gradle
project.ext.envConfigFiles = [
debug: ".env",
release: ".env",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
...
android {
...
defaultConfig {
...
resValue "string", "build_config_package", "com.yourApp.packageName"
}
iOS
Go to Product
> Scheme
> Edit Scheme...
in the left panel Build
> pre-actions
add a new run script action
and add the code below ( to generate the GeneratedDotEnv.m
)
xcodebuild -project "${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig.xcodeproj"
then in your Pod
file add this line under your target
pod 'react-native-config', :path => '../node_modules/react-native-config'
and last step :
cd ios && pod install
Upvotes: 3