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
react-native-config example does not read variables from .env file or .env.prod #170
Comments
Did you do the Android setup? https://github.com/luggit/react-native-config#extra-step-for-android |
Same problem with
Working fine with |
Can you paste the output of When it's setup properly you can see it's reading (or failing to read) the env like:
|
It's fine with
But when I want to build an apk for release,
|
No fail spotted 🤔
|
Oh! How are you setting it to use |
ah hmm. Does it work if you |
I also have a .env, so
How I use it in my app :
Logs when I launch my app (signed) : |
I also see this |
Ah weird, so you see "Reading env from .env" when you call I never had this issue myself, but wondering if it's because of a custom applicationId/applicationIdSuffix, or Proguard. Have you checked the advanced setup and troubleshooting sections here? |
Maybe clean the build too to be sure: |
I change my |
Ah, phew! Surprised this didn't cause a compilation failure in 1st place :| hopefully we can fix this at some point. But thank you! Closing this for now. |
I am unable to solve this problem. with the provided solutions |
It seems the issue for me I needed to add
|
Have the same problem. I can get environment variable when just run react-native run-android, but if I try build sign apk a just can't get only developer values. (( |
For use this constants you mast exported it. And you can't use other assemble type, only assembleRelease. If you create other build type in build.gradle, simple copy release, this don't work.
Please add in documentation section "How install manual" - because I spend many time for run lib, because |
I was days trying to figure out why my react Config variable was always empty. That solved it. This NEEDS to be added to the README! Also the import is: |
for me I was using build variants and adding BuildConfig to progurad file solved it. |
I already had |
for react native 0.60.0, I have fixed it adding
it seems that react native autolinking feature not implemented in this package yet |
When we select APK from app bundle in the deploy option, Gradle runs a task named |
@pradhul Can you explain how you did that? |
For I installed running the following:
And then I made the manual updates that the README specifies for Android and iOS:
And everything just... worked. In both iOS and Android. So I think the only thing that's needed is notes in the
Or something to that effect. EDIT: I've observed this behaviour for both the current published version and the most recent unpublished version ( |
@bericp1 I started using RN 0.60.5 and for simple I still get: but |
@aecc ifg I add and then add I get Am I missing an install step? |
i tried all but nothing resolve my issue , still get undefine |
can you give some example that where we run that command because export give error , or may be some other things |
so you need to change aplicationId to default id..?? |
I was updating my app from React Native 0.57 to 0.61.3 ran into a lot of issues and unlinked all packages, since newer React Native introduced auto-linking.
|
It works for me: Adding |
I got this working through some experimentation. For me, I'm using In your
Replace with:
Or in my case and using
|
Works! |
@LuizFBrisighello Hi, did you resolve your undefined issue with Product Flavor? I am getting undefined too. |
me too! what's the solution? |
@dipeshkoirala21 Sorry for the late answer and its not a very good news, at the time I figured out but now it was over a year ago.. I really dont remeber. Im still on RN 0.60.5, using
|
it works for us |
In our case, we could not read the .env file because we used a suffix for our application name,
|
After I installed react-native-config and added the .env file to my project's root, I found the environment variables were still not included in the Config object.
In a summary, what I did to make it work:
My changes can be found from this commit. Hope it helps. |
work for me |
this worked for me. |
Thanks, it was also my issue. You can use the
|
Figured the issue is related to different applicationId. Only when different this plugin won't work. |
Hey, this is working for debug mode, but not for staging/prod for Android. I've done everything being provided above. Any workaround? Also, what if I want to access |
Is there a solution to this? I get this in the output:
this all works without variant=release. |
My environment
|
Its simple but unexpected. Doesnt use import { SOME_ENV } from 'react-native-config'; when build it, the lib doenst reconize it. You need always use: import Config from 'react-native-config'; so Config.SOME_ENV |
I am also facing an issue. |
We were having this issue because of Proguard, as far as I could tell. Disabling Proguard in our release builds fixed it, but obviously we wanted Proguard back in. I fixed this issue using the The important part is:
|
Finally i have Solved the IssueMY Packages and Configs:
To Ceate the REACT_NATIVE_CONFIG https://github.com/luggit/react-native-config follow the Above setup to to install and After installetion follow this
Then
make Changes as your Requirements THEN add these Configs just Above the : defaultConfig
also don't Forget tio ADD at the end of your defaultConfig
THEN ADD in the buildTypes.debug in the dependencies add
NOTE : Please replace com.transportsimple.appId with your APP Package Your are DONE for the ANDROID Setup of the .env File Now to Run the APP Please run the following command.
to Build the APK Please do the Following:
To Build AAB File run Folllowing :
Thanks for Refering this 💯 👍🏻 🥇 👍🏻 |
This works for me, Thanks a lot. |
Windows 10
Mobile Device Nexus 6P
react-native-cli: 2.0.1
react-native: 0.38.1
SET ENVFILE='.env.prod' && react-native run-android
when i run above line on example application its not reading anything from .env file.
The text was updated successfully, but these errors were encountered: