Search code examples
react-nativedotenv.envreact-native-config

react-native-config not working on android - RNCConfig Module tried to override RNCConfigModule


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.


Solution

  • 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",