React-native-config: Android variant release not working

Created on 10 Feb 2018  路  9Comments  路  Source: luggit/react-native-config

I have a project with multiple flavors the build.gradle file looks like this

project.ext.envConfigFiles = [
        flavorx: ".env.flavorx",
        flavory: ".env.flavory",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

android {
    ...
    productFlavors {
        flavorx {
            applicationId 'flavor.x'
            resValue "string", "build_config_package", "default.package.name"
        }
        flavory {
        }
    }
}

in the debug mode everything works fine, and each flavor get its specific config.

but in release mode the .env file is not loaded and I get empty values, even though this line appears in the terminal

Reading env from: .env.flavorx

I also tried this starting the build using this command
ENVFILE=.env.flavorx ./gradlew assembleFlavorxRelease
and the result is similar

any suggestions ?

Most helpful comment

It was just a proguard issue. Resolved by adding this line to proguard-rules :

-keep class default.package.name.BuildConfig { *; }

All 9 comments

It was just a proguard issue. Resolved by adding this line to proguard-rules :

-keep class default.package.name.BuildConfig { *; }

@sodaoud does default.package.name get somehow magically substituted?

@YarekTyshchenko mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

I am having the same issue, but even after configuring everything as in the docs, it just don't work here :(

I see that even generates the resource xml file with the correct values in the output folder, but on react native code the Config object is completely empty

Same situation like @vitorreis mentioned: run-android (not release mode), generated.xml contains my env values, but object in runtime is empty... For ios it works fine.
Did anyone solve this already...?

@frankiewiczkamil I couldn't get it working, so in the end I used the library: https://github.com/zetachang/react-native-dotenv

I've had the same problem, setting proguard-rules didn't help, because I had proguard already disabled.

what helped was setting a fixed build_config_package in android/app/build.gradle

defaultConfig {
    ...
    resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML"
}

hope this helps

I changed the original applicationId from the app and also the package name in the manifest and both are the same and the @sodaoud solution works for me thanks a lot.

I really don't get the build_config_package string there... is this exactly word or should I use the env string I set?

.env:
APP_ID=com.appname.here

resValue "string", "build_config_package", project.env.get("APP_ID")

or

resValue "string", "APP_ID", project.env.get("APP_ID")

Was this page helpful?
0 / 5 - 0 ratings