skip to Main Content

I followed the instructions on the react-native-config package but Im getting the following error:

Native module RNCConfig Module tried to override RNCConfigModule. Check the getPackages() method in MainApplication.java , it might be that module is being created twice.

If I just install the package and don’t do the native steps, it doesn’t break like this but my Config on android is empty.

2

Answers


  1. Chosen as BEST ANSWER

    Through trial and error of commenting out different combinations of the native instructions and doing many gradlew cleans and reset cache (and ultimately having to delete my android/.gradle folder and click Sync Project with Gradle files in Android Studio to remove a persistent ghostly remnant of react-native-config after completely removing the package and code, I was encouraged by this thread: https://github.com/lugg/react-native-config/issues/741#issuecomment-1676199644

    I ended up only adding this to my app/build.gradle file and didn't add any of the other native Android parts as they listed in the instructions. This is how the top of it looks now:

    apply plugin: "com.android.application"
    apply plugin: "org.jetbrains.kotlin.android"
    apply plugin: "com.facebook.react"
    
    apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" // I added only this
    

    I'm using "react-native": "0.73.2", "react-native-config": "1.5.1",


  2. You have to create .env file in root directory of your project.
    and add these line in your android/app/build.gradle file.

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

    for more details
    https://github.com/lugg/react-native-config/blob/master/Example/android/app/build.gradle

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search