After doing all the steps and going throw issue, it always return an empty object. if any one have proper configuration for RN 0.59 please comment.
Yep seems to fail with react-native v 0.58.2 as well
If you add this line resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML" to your defaultConfig, you should remove it.
I'm having the same problem on Android. Anyone found a solution? In BuildConfig the variables are present but not when reading from Config (in js). iOS works.
this problem is related to JAVA version in your system, i was running on java 9 and it was'nt ./gradlew clean or assembleRelease were not reading the passed environment file, then i downgraded to java-8 and it worked like a charm.
java -12 gave a new error so i avoided that!
in my case, it didn't working because i had this in my react-native.config.js:
module.exports = {
assets: ['./src/assets/fonts'],
dependencies: {
'react-native-config': {
platforms: {
ios: null,
android: null,
},
},
},
};
By removing android: null, it works fine on android :)
@Sathyanarayan09 @Samykills what version of react-native-config are you using?
I have:
"react-native": "0.59.8"
"react-native-config": "0.11.5"
and works great.
"react-native": "0.59.8"
"react-native-config": "0.11.5"
I get Reading env from: ../../.env with no errors. But my config is always empty.
works fine on iOS
Any update? I have the same problem.
IOS works fine..
react-native: 0.59.1
Hi everyone.
After seeing "react-native-config" stop working on Android, I started investigating why.
I have seen many comments with the same problem as described by @Sathyanarayan09 .
Only in Android, the plugin does not read my .env files (in my case .env.prod .env.staging .env.dev correctly declared in "project.ext.envConfigFiles").
I finally found my solution.
If in Android Studio -> Edit Configurations... -> Tab General -> Installation Options, I have "APK from App Bundle" option selected, just don't read my .env files.
But if I use the "Default APK" option, it works correctly again as it always did. Weird...
I hope it helps.
@Sathyanarayan09 I might be wrong but I think react-native-dotenv only works for your JS, so the variables are not accessible from native code files
For anyone struggling with this, I seemed to fix this (馃馃徎) by adding resValue "string", "build_config_package", "com.blah.blah" to my defaultConfig in app/build.gradle.
The instructions suggest adding resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML, but for some reason this didn't work with the .xml on the end
See troubleshooting https://github.com/luggit/react-native-config#problems-with-proguard here.
It works for me on react-native: 0.61.2
and don't forget rename mypackage in com.mypackage.BuildConfig.
I use "react-native": "0.59.1"
react-native-config doesn't work on android's bundleRelease, it seems like it is very fragile library.
To fix the issue - remove react-native-config and instead of ENVFILE=.env.prod use echo 'export default "prod"' > src/env.js and config.js:
import env from './env.js'
var config = {
dev: { host: 'http://localhost:3000/'},
stag: { ... },
prod: { ... }
}
export default config[env]
It works for me.
Most helpful comment
I'm having the same problem on Android. Anyone found a solution? In BuildConfig the variables are present but not when reading from Config (in js). iOS works.