Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aledustet opened this issue Jul 7, 2020 · 11 comments

Comments

@aledustet
Copy link

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:

  • We added the appId for the BT build to the proguard-rules
  • We tried leaving the buildConfig alone and only using one .env file
  • We hardcoded the appID across the manifests inside the android app
  • We switch the MainActivity to just point to the BT version appID
@hlandao
Copy link

hlandao commented Jul 12, 2020

Same issue here on RN => 0.0.63.

@haseebeqx
Copy link

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
Copy link
Author

@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
Copy link

@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
Copy link
Author

@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
Copy link

zabojad commented Aug 25, 2020

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

@humbkr
Copy link

humbkr commented Jan 5, 2021

I had the same issue when setting up flavors with an applicationIdSuffix, and the solution was to specify a resValue like this comment mentions: #223 (comment)

@aprilmintacpineda
Copy link
Contributor

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
Copy link

congduong97 commented Jan 17, 2022

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
Copy link

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

@mthahzan
Copy link

mthahzan commented Oct 9, 2024

Had the same issue and got it fixed by doing this.

productFlavors {
    dev {
        applicationIdSuffix ".dev"
        resValue "string", "build_config_package", "<your package name>" // Add this line
    }
    staging {
        applicationIdSuffix ".staging"
        resValue "string", "build_config_package", "<your package name>" // Add this line
    }
    production {}
}

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants