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

Config is returning an empty object {} despite correct setup in Android #824

Open
DhanushKG-25 opened this issue Dec 10, 2024 · 0 comments

Comments

@DhanushKG-25
Copy link

Description:

I am encountering an issue where Config from react-native-config is returning an empty object {}, even though the .env file and build configurations are properly set up. I have followed the documentation and verified all steps, but the issue persists.


Steps to Reproduce:

  1. Installed react-native-config in my React Native project.
  2. Created a .env file in the project root with the following content:
    APP_NAME=SampleApp
    PRODUCT_BUNDLE_IDENTIFIER=com.example.app
    PRODUCT_NAME=Sample Product
    APP_FOLDER=sample-folder
  3. Added the following configuration in android/app/build.gradle:
    project.ext.envConfigFiles = [
        debugFlavor: ".env.sample-debug",
        releaseFlavor: ".env.sample-release"
    ]
    
    apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
  4. Built the app using:
    ./gradlew assembleDebugFlavor
  5. Checked the Config object in JavaScript:
    import Config from 'react-native-config';
    console.log('Config:', Config); // Output: {}

Expected Behavior:

The Config object should contain the variables from the .env.sample-debug file, e.g.:

{
   APP_NAME: "SampleApp",
   PRODUCT_BUNDLE_IDENTIFIER: "com.example.app",
   PRODUCT_NAME: "Sample Product",
   APP_FOLDER: "sample-folder"
}

Actual Behavior:

The Config object is returning an empty object:

{}

Environment:

  • react-native-config version: 1.5.3
  • React Native version: 0.72.4
  • Node version: 16
  • Gradle version: 8.1.1
  • Android Studio version: Ladybug
  • Package Manager: [email protected]

Troubleshooting Steps Taken:

  1. Verified that .env.sample-debug exists in the project root and has no formatting issues (e.g., no spaces around =).
  2. Confirmed dotenv.gradle is being applied by adding a debug log:
    println("Using ENV_FILE: " + project.envConfigFiles[project.getProperty('ENVFILE')])
    Output showed the correct .env file is being used.
  3. Checked BuildConfig in the decompiled APK. The variables from .env were not embedded in BuildConfig.
  4. Restarted Metro with yarn start --reset-cache.
  5. Updated to the latest compatible version of react-native-config.
  6. Tried a minimal .env file (e.g., TEST_KEY=hello-world), but Config.TEST_KEY was still undefined.

Additional Notes:

  • This issue occurs consistently for both debug and release builds.
  • Using ./gradlew clean and rebuilding did not resolve the issue.
  • I am unable to find the variables in BuildConfig after decompiling the APK.
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

No branches or pull requests

1 participant