I’m experiencing an issue with the react-native-config library in my React Native project where it works as expected on Android, but fails to function on iOS.
Environment:
React Native version: 0.69
Node version: 20
react-native-config versions tested: 1.5.1 to 1.5.3
Xcode version: 15.1
Testing device: iPhone 11
iOS version on device: 18.0
Issue Details:
After installing react-native-config and following the setup instructions, I confirmed that environment variables work correctly on Android, but on iOS, they do not seem to load or return undefined. I have tried several configurations to resolve this, but the issue persists.
Steps Taken to Resolve:
Ensured that my .env file is properly set up and contains the necessary environment variables.
Verified that the library is linked correctly and rebuilt the project in Xcode after cleaning the build folder.
Followed the video tutorial at YouTube video link ( https://www.youtube.com/watch?v=8lA0wP-0vEo&t=154s ) to double-check my configuration steps for iOS.
Code Example:
javascript
Copy code
import Config from ‘react-native-config’;
console.log(Config.MY_VARIABLE); // Works on Android but logs undefined
on iOS
Additional Notes: I’ve also checked that the variables are correctly referenced in the Info.plist file as recommended in some guides, but this has not resolved the issue.
Question: What additional configurations or troubleshooting steps should I consider to get react-native-config working on iOS? Are there any iOS-specific requirements for this library that I might have missed?
Testing with Different Versions of react-native-config:
I installed and tested with the latest three versions of the react-native-config library (1.5.1, 1.5.2, and 1.5.3) to see if an earlier or later version would work on iOS. Despite these version changes, I still encountered the same issue: environment variables work on Android but not on iOS.
Double-Checking the Configuration:
I thoroughly reviewed my configuration setup for react-native-config multiple times to ensure all required steps were followed. This included:
Verifying that my .env file is in the root directory and that the variable names are in uppercase.
Ensuring that the react-native-config setup in Podfile is correct, and running pod install after each change to make sure dependencies are up to date.
Rebuilding the iOS project in Xcode and cleaning the build folder after each configuration adjustment to rule out any residual build issues.
Reviewing Online Resources and Documentation:
I consulted the official react-native-config documentation to verify that I hadn’t missed any steps specific to iOS.
Additionally, I watched the setup video on YouTube (link to the video) to cross-check my setup and ensure I followed the configuration steps correctly.
Attempting Troubleshooting Solutions Found Online:
After Googling the issue, I tried various troubleshooting tips found on Stack Overflow, GitHub issues, and other forums. This included:
Adding variables directly in Info.plist as recommended in some discussions.
Checking that react-native-config is linked correctly and visible in the Build Phases and Link Binary with Libraries sections of my Xcode project settings.
Attempting to manually set environment variables in the scheme settings in Xcode for the iOS build.
Despite these efforts, the environment variables still show up as undefined when the app is run on iOS, although they work fine on Android.