lugg / react-native-config

Bring some 12 factor love to your mobile apps!
MIT License
4.81k stars 657 forks source link

Multiple flavors for android build config results in empty `Config` object on the react native side #467

Open aledustet opened 4 years ago

aledustet commented 4 years ago

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.

Things we have tried:

hlandao commented 4 years ago

Same issue here on RN => 0.0.63.

haseebeqx commented 4 years ago

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 { *; }
aledustet commented 4 years ago

@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.

haseebeqx commented 4 years ago

@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.

aledustet commented 4 years ago

@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

zabojad commented 4 years ago

In our case, it doesn't work when we use applicationIdSuffix in app build.graddle...

humbkr commented 3 years ago

I had the same issue when setting up flavors with an applicationIdSuffix, and the solution was to specify a resValue like this comment mentions: https://github.com/luggit/react-native-config/issues/223#issuecomment-441662643

aprilmintacpineda commented 3 years ago

I'm getting this error: Could not get unknown property 'dev' for DefaultConfig_Decorated when I moved apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" on the top of the file, I think it's because it's messing with my build config flavors:

flavorDimensions "version"
productFlavors {
    dev {
        applicationIdSuffix ".dev"
    }
    staging {
        applicationIdSuffix ".staging"
    }
    production {}
}

Can anyone help?

congduong97 commented 2 years ago

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 { *; }

Thanks, It worked with my jitsi-meeting project.

millro04 commented 2 years ago

@aledustet have you found a resolution to this? Facing the same issue as you