I was using react-native-config to support multiple flavours for multiple release builds. I've created multiple .env files also and all the debug builds are able to access it and getting the configs. There is no problem in the debug builds but when it comes to release builds they are not getting the configs from the env file. I tried to toast the config and it shows empty string.
This might be mostly problem with Proguard.
When Proguard is enabled (which it is by default for Android release builds), it can rename the BuildConfig Java class in the minification process and prevent React Native Config from referencing it. To avoid this, add an exception to android/app/proguard-rules.pro:
-keep class com.mypackage.BuildConfig { *; }
mypackage should match the package value in your app/src/main/AndroidManifest.xml
file.
Solution 1: Make def enableProguardInReleaseBuilds = false in android/app/build.gradle file.
Solution 2: Make def enableProguardInReleaseBuilds = true in android/app/build.gradle file and then *add -keep class com.mypackage.BuildConfig { ; } in the file path android/app/proguard-rules.pro
Replace com.mypackage with your project’s package name.
© 2022 - 2024 — McMap. All rights reserved.