React-native-config: Config Object Is Empty In App With RN v63.2

Created on 14 Aug 2020  路  10Comments  路  Source: luggit/react-native-config

The config works just fine and is accessible natively in the Android Java environment but using the values in the actual React Native javascript code comes up with an empty object.

Packages used:
"react-native": "0.63.2",
"react-native-config": "^1.3.3",

sample code:

import Config from "react-native-config";
console.debug("Starting application: " + JSON.stringify(Config));

Result:
[Fri Aug 14 2020 13:01:40.307] DEBUG Starting application: {}

Most helpful comment

[SOLVED]
I was also facing the same issue, if you are using applicationIdSuffix then add this

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

All 10 comments

Checklist for you to check your project:

  • Add this in android/app/build.gradle
    apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
  • Check in in android/app/build.gradle
    defaultConfig { applicationId: <ApplicationID> } ApplicationID must match your pakage in AndroidManifest, MainApplication.java and MainActivity.java
  • Check content of the .env file, make sure there is no SPACE between key and value
    KEY = ABC -> should be KEY=ABC ( No space )

Hi! I have the same issue with

"react-native": "0.63.2",
"react-native-config": "^1.3.3",

It works fine on iOS but Im getting an empty object on Android

Same here with RN 0.61.5

@JavierLaguna I have same issue with you

I suggest you guys to follow the README carefully. This is not just add and run.

I have the same issue

Same issue here, I followed all steps in the README, but still, it is not working for Android, it just works for IOS

[SOLVED]
I was also facing the same issue, if you are using applicationIdSuffix then add this

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

[SOLVED]

1. go to android folder
run : gradlew clean

2 . go to project folder 
run : react-native link react-native-config
  1. adding new line at : android/app/build.gradle
project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"
// config .env
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" == here
android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.tutorialrn"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        resValue "string", "build_config_package", "com.tutorialrn" ==> here
    }
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    //config .env
    implementation project(':react-native-config')` ==> here

now i can get variable from ( .env ) file

from :
"react-native": "0.63.3",
"react-native-config": "^1.3.3",

After upgrading to react-native-config v1.4.1 it seems to work again fine!

Was this page helpful?
0 / 5 - 0 ratings