We are using RN => 0.61.5, and the latest version of react-native-config
This is an open-source project, here is [the repo]. There is a split for two flavors of the applications, one BT and one GPS, on the iOS version, the pre-build scripts copying the right env file on the right Scheme works and each version of the app loads the correct set of env variables. When the Android version builds for the GPS flavor the environment variables are made available on the react-native side and everything works. Is worth noticing that the default and original configuration was made for the GPS side, using the original appId.
When the BT flavor builds, if we spoof inside the dotenv.gradle the buildConfig is picked up and the right env file is found, we can see it in the build output and if we print the env that is being used inside that file it has all the right values. However, as soon as the app builds our Config imported from react-native-config is empty.
proguard-rulesbuildConfig alone and only using one .env fileSame issue here on RN => 0.0.63.
Check if proguard is enabled, if so you have to add this in android/app/proguard-rules.pro: replace mypackage with equivalent package name.
-keep class com.mypackage.BuildConfig { *; }
@haseebeqx we have proguard enabled https://github.com/Path-Check/covid-safe-paths/blob/f8195a3a91301d182e0df7ab65f1b59560a75a36/android/app/proguard-rules.pro#L13 on the default flavor of the app all environment variables are available, is just when we change the bundle identifier that the Config is undefined.
@aledustet Why you need to bundle identifier?. If it is for rebranding I think you can add a README instruction for user to update this config also.
@haseebeqx the way the product is set up, we need to handle two different applications for different flows. Each one is a different product. We are using the different configuration files for different bundle identifiers using schemes on the iOS side. This behavior allows us to have one 'environment' for the iOS native code and the javascript code. The same should be true for the android native code. The equivalent to schemes on android is the product flavors, and those are configured in the same way. Hope this answers your question
In our case, it doesn't work when we use applicationIdSuffix in app build.graddle...
Most helpful comment
Check if proguard is enabled, if so you have to add this in
android/app/proguard-rules.pro: replacemypackagewith equivalent package name.