React-native-config: BUG ANDROID

Created on 24 May 2017  路  11Comments  路  Source: luggit/react-native-config

IOS it ok, but android not ok.
my file .env
URL=localhost:3000

I used to "import Config from "react-native-config" in js code
-> IOS then Config = {URL="localhost:3000" }
-> Android then Config = {}

Most helpful comment

Allright, following the above suggestions + adding this line to android/app/proguard-rules.pro solved it for me:

-keep class com.mypackage.BuildConfig { *; }

(where com.mypackage is your package name)

Basically following the readme in other words 馃槃


So to recap:

  • In android/app/build.gradle (right after apply plugin: "com.android.application"):

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

  • In MainApplication.java:
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.asList(
    ...
    new ReactNativeConfigPackage(),
    ...
  );
}
  • In android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

(where com.mypackage is your package name)

All 11 comments

Is there any news or workarounds on this?

I had the same issue too, fixed following some instructions provided here : https://github.com/luggit/react-native-config/issues/32

Don't forget this part https://github.com/luggit/react-native-config#extra-step-for-android on Android setup, looks like react-native link command was not adding the line automatically.

Not working, I'm waiting for the new version

You can check these codes in MainApplication.java. If it is not exist, you can add them

import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;

new ReactNativeConfigPackage();

@ozsirma where are you calling new ReactNativeConfigPackage();

@hdchan, as @ozsirma wrote in MainApplication.java:
` @Override protected List<ReactPackage> getPackages() { return Arrays.asList( ... new ReactNativeConfigPackage(), ... ); }

@ozsirma @chrusart
I am also facing same issue
It is there in MainApplication.java still it is not working in android it is giving config={}

Allright, following the above suggestions + adding this line to android/app/proguard-rules.pro solved it for me:

-keep class com.mypackage.BuildConfig { *; }

(where com.mypackage is your package name)

Basically following the readme in other words 馃槃


So to recap:

  • In android/app/build.gradle (right after apply plugin: "com.android.application"):

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

  • In MainApplication.java:
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.asList(
    ...
    new ReactNativeConfigPackage(),
    ...
  );
}
  • In android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

(where com.mypackage is your package name)

@ozsirma Thanks, that was my problem :+1:

Thank you folks! Closing then, let me know if the problem persists.

@Sundin I still get error: package com.lugg.ReactNativeConfig does not exist

Is this package being maintained? Anyone know of an alternative?

Was this page helpful?
0 / 5 - 0 ratings