React-native-config: Still getting undefined - Android/Windows Enviroment

Created on 28 Mar 2018  Â·  15Comments  Â·  Source: luggit/react-native-config

Hi there. I still can't get this library working. I think i tried everythig.

1) npm install --save react-native-config
2) react-native link
3) In _android/app/build.gradle:_
After the line: apply plugin: "com.android.application"
ADDED: => apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
4) In _android/app/build.gradle:_
Like the issue https://github.com/luggit/react-native-config/issues/228 says:
compile project(':react-native-config')
5) Get the app run with SET ENVFILE = .env && react-native run-android (also with SET ENVFILE = '.env' && react-native run-android but getting NOT .env file detected)

Let me say that steps 3 and 4 i make them in text editor and building and running the app in command prompt with no problems.
If i want to make these changes on Android Studio i can't compile because the line apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" is getting troubles.

Any idea?

Most helpful comment

Guys, I followed the instructions correctly, but I realized that react-native link react-native-config hadn't made all of the expected changes, because my MainApplication.java was altered to integrate react-native-navigation. So the package ReactNativeConfigPackage was not being initialized. So all I needed to do was include it in my package list, just as described bellow:

...
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;

public class MainApplication extends NavigationApplication {
  ...

  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
            ...
            new ReactNativeConfigPackage()
    );
  }
}

All 15 comments

I've got the same issue on Ubuntu 16.0.4 with react-native 0.52 and react-native-config 0.11.5

@ntaboadaclapps did you find a solution?

Looks like drowgrading to 0.8* works for me too.

I tried drowgrading the version but still getting undefined :(

I've fixed it by using react-native-dotenv instead to read the .env file. Works perfect for me, not sure if it's able to read the .env file on the release build, but it works on dev. Maybe a temporary work around.

Guys, I followed the instructions correctly, but I realized that react-native link react-native-config hadn't made all of the expected changes, because my MainApplication.java was altered to integrate react-native-navigation. So the package ReactNativeConfigPackage was not being initialized. So all I needed to do was include it in my package list, just as described bellow:

...
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;

public class MainApplication extends NavigationApplication {
  ...

  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
            ...
            new ReactNativeConfigPackage()
    );
  }
}

FIXED! Combining @gabrielvcbessa and @djalmaaraujo solutions i fixed.! Adding the steps that i mention at the beggining.

Im still getting undefined although the package is loaded properly in MainApplication.java. Need help.

Did you add this line line 2 of the build.gradle in the android/app/src
directory after react-native link?

apply from: project(':react-native-config').projectDir.getPath() +
"/dotenv.gradle"

On Fri, Apr 20, 2018 at 9:58 AM, renielDev notifications@github.com wrote:

Im still getting undefined although the package is loaded properly in
MainApplication.java. Need help.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/luggit/react-native-config/issues/243#issuecomment-383104694,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEKtj4Y4sAd0NmyfcUnPq0xkzlboYBMCks5tqemFgaJpZM4S-xZe
.

I were getting undefined config object in android because I had changed our application id in build.gradle when I changed it in manifest file and changed package name accordingly then I got values in config object.

Thanks @OkancanCosar , that solved my problem !

Tried solutions above but issue still here :(

On Android/Windows/Powershell, if anyone is still having the issue where set ENVFILE=.env.production; ./gradlew assembleRelease prints out "Reading env from: .env" even though you set everything up right...

Set your ENVFILE like this: $env:ENVFILE=".env.production"

This is a combination of every solution out there. So if you haven't set up for Windows/Android in the README or haven't added new ReactNativeConfigPackage() yet. Do that first. This solution only gets dotenv.gradle to read your ENVFILE variable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpereira picture rpereira  Â·  3Comments

jemise111 picture jemise111  Â·  4Comments

francisrod01 picture francisrod01  Â·  3Comments

Quadriphobs1 picture Quadriphobs1  Â·  3Comments

kidnapkin picture kidnapkin  Â·  3Comments