Open novito opened 6 years ago
Same here.
.env
API_URL=http://
.js
import Config from 'react-native-config';
Config.API_URL // undefined
Problem fixed!
I haven't seen the Setup; Running react-native link react-native-config
it worked.
react-native link react-native-config didn't do everything for me, but making the changes manually sorted it out
On 11 August 2017 at 21:59, Pablo notifications@github.com wrote:
Problem fixed!
I haven't seen the Setup https://github.com/luggit/react-native-config#setup; Running react-native link react-native-config it worked.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/luggit/react-native-config/issues/143#issuecomment-321794990, or mute the thread https://github.com/notifications/unsubscribe-auth/AAY4_pIqFseOTk8xou1Qmfto3mCPaQMtks5sXEIqgaJpZM4Ov9nh .
having the same issue. @elyobo how you fixed that?
Carefully went through the instructions and checked that I'd done them all correctly. I realised that the react-native link react-native-config
hadn't made all of the expected changes, possibly because my MainApplication.java was already heavily modified to integrate react-native-navigation
. My recollection (possibly wrong) was that I had to manually go in and add new ReactNativeConfigPackage()
to the last of packages returned in MainApplication::getPackages()
.
How are you creating .env
file?. This was happening to me when I was creating it from new Text Document, this does not recognize the .env
extension. You should create the .env
file by terminal.
cd Users/ProjectDir/
touch .env
or e.x touch .env.dev
I think this should be described on the Readme
Thanks guys, I was able to fix this issue. There were multiple issues with my project. I was using sudo in all of my commands and it caused some strange issues in auto generated files. Wasted lots of times yesterday and today eventually had to scrape my repo and re-clone it and build it from scratch without sudos. Now it's working. Also, there were issues in linking. First, I was using this plugin without running the link command. Yesterday figured it out and ran link command but since there were strange sudo based issues going on, so it did not work well.
So to summarize, use react-native commands without sudo and do run link commands. Hopefully, things will work.
I'm having the same issues, I followed all the steps for ios and it's still not working. I'm using WebStrom and running via terminal I have tried both react-native run-ios --scheme CCMobileApp Staging
and react-native run-ios
i am also facing the same issue. Config object is empty. Does anyone find any solution for it
i have the same issue after upgrading to RN 0.47. tried upgrading to react-native-config to 0.5.0 without luck.
+1 (react-native: 0.45.11, react: 16.0.0-alpha.12, react-native-config: ^0.6.0 / platform: android, development env: windows 10)
I fixed it by unlinking and linking it again.
react-native unlink react-native-config
react-native link react-native-config
The only problem was i configured it wrongly before and linked it . And later even though fixing the configuration it was not working. Then unlinking and relinking worked
Tried unlink and link getting the following error
ENOENT: no such file or directory, open '/Users/Almog/Full-Time-Employment/Construction-Cloud/RnD/CCMobileApp/android/app/src/main/java/com/ConstructionCloud/CCMobileApp/MainApplication.java'
Tried to re-link. Also tried version 0.6.0. I get no errors, but i always get back an empty object for Config. rolling back to RN 0.44 and react-native-config 0.3.1 fixes it.
Delete the app from your device or simulator, reinstall and fixed~
@DavidKongDesheng that did not work, tried it twice. Everything works fine if you run it from Xcode but that kind of sucks prefer to run everything from terminal.
I was able to get it working myself. Make sure your env files are in the project root directory and not a subfolder.
Examine the ruby script:
# find that above node_modules/react-native-config/ios/
raw = File.read(File.join(Dir.pwd, "../../../#{file}"))
The location where react-native-config
is looking for your .env* files is definitively in your project root directory.
Once I moved my config files to the correct location, I was able to access the config values.
Alternatively, for ios, if you want your files in a different directory you can modify the prebuild script to point to the directory you want to use.
I changed echo ".env.dev" > /tmp/envfile
to echo "app/.env.dev" > /tmp/envfile
so that I can put my config files in the project-root/app
dir.
I hope this helps.
the same issue
I'm having the same issue with v0.6.1. I've ran all my linking correctly (I see the xcode project with the library, etc). However, my Config from my import is an empty object.
The only solution for me was to remove use_frameworks!
from podfile.
After removing that line and reinstalling my pods it started to work as expected
Just dropping a note here to hopefully save someone from doing the same thing I did:
Don't put any spaces between the variable name, the equals and the value. Doing this:
VARIABLE_NAME = 'somevalue'
Will cause the GeneratedInfoPlistDotEnv.h
file to silently exclude the value. Be sure that your .env looks like this:
VARIABLE_NAME='somevalue'
+1 cannot get it to work. I get the same problem
I have tried running the link command, different simulators and doing everything stated in the Setup section in the Readme. I also deleted the app multiple times and re-installed it. But nothing works.
I managed to solve this by running these commands inside my project:
$ rm -rf $TMPDIR/react-* && watchman watch-del-all && rm -rf ios/build && rm -rf node_modules/ && npm cache clean --force && npm i
$ react-native link react-native-config
$ react-native run-ios
Adding the following line to android/app/build.gradle
fixed it for me
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
I had the same issue, but @MattHall's solution fixed it for me.
An addition for (at least) React Native v0.50.4: react-native link
did work for neither Android nor iOS. Android required the addition to android/app/build.gradle
described by @acharlop. For iOS, ReactNativeConfig.xcodeproj
needs to be manually added to Libraries and libReactNativeConfig.a
added to Build Phases -> Link Binary With Libraries.
My problem was that react-native link
worked, but I already had multiple targets in Xcode and the libReactNativeConfig.a was not linked in my development environment. Thanks @nlindroos for your comment above. Does anybody know how to add a new node package to a project and link it to both or possible even more targets?
@RubenO88 If react-native link
doesn't do the necessary configuration automatically for a certain package, you can perform steps similar to the ones mentioned above, separately for each target. The required steps naturally differ between different packages.
Guys, I think this only works when you relaunch a project. ie making modifications to the .env file doesn't take effect until you run the build all over again. Relinking the native code might do it once, by coincidence, but what if you make changes, reload, make more changes, etc? I don't think it takes effect on-the-fly.
@tmaly1980, is right! You'll need re-build the project every time that your .env
changes.
@MattHall ,thank you ! You saved my APP!
@elyobo thank you a lot! react-native link
tried to use MainApplication.java
that doesn't belongs to the project, so I've manually added new ReactNativeConfigPackage()
like you mentioned. Just wanted to add that it shold be imported with import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
For people running into this issue on Android using either applicationIdSuffix
or build flavors, this is also a symptom of not properly setting the build_config_package
resValue
to your base package name (i.e. without the suffix) like the "Advanced Android Setup" section in the readme describes. See also #15.
This is documented but may be hard to catch since the error message (ReactNative: ReactConfig: Could not find BuildConfig class
logged in android/src/main/java/com/lugg/ReactNativeConfig/ReactNativeConfigModule.java
) only shows up in logcat and doesn't explicitly cause a crash.
I'm seeing this issue when running npm test. Using react-native-config works when running my app though. I have a .env file in the root dir of the RN app which works. When running my test, it doesn't seem to find the .env file thus all the variables are undefined. I am assuming it is a matter of either creating another .env file for the tests specifically (but I don't know where to actually put that), or somehow specify the original .env file (also not sure how to do that).
Same issue for me. Works on iOS, but getting BuildConfig
class not found error on Android.
D/ReactNative: ReactConfig: Could not find BuildConfig class
I have confirmed that the package name matches the applicationId, no suffix is being used. Also tried still manually adding the proper build_config_package
resValue to no avail.
Thanks @AlmogRnD, thats worked to me!
@rhogeranacleto I still have problems, How did you solve it? android release apk: enabled minifyEnabled true D/ReactNative: ReactConfig: Could not find BuildConfig class
I found out that react-native run-ios
works for iOS, but if you want Android to use the scheme, you had to build it using Android Studio, as react-native run-android
did not manage to build the env file into BuildConfig
for some reason. Mysteries. Eventually gave up on react-native.
On iOS I managed to fix this by changing the order of Linked Frameworks dan Libraries. Just drag libReactNativeConfig.a
above libReact.a
, recompile your project and it works.
This tutorial helped me: https://medium.com/differential/managing-configuration-in-react-native-cd2dfb5e6f7b.
@elyobo Thank a lot, I've manually added new ReactNativeConfigPackage(). it's worked
Same here.
"react": "16.6.0",
"react-native": "0.57.4",
"react-native-config": "0.11.5"
each time i install this package, this issue shows up. And i still don't know how to resolve it =)) Please, anyone ...
Yes we should add new ReactNativeConfigPackage()
but still doesn't solve the problem for me.
@bericp1 solotuion works for me. To conclude the solution
new ReactNativeConfigPackage()
defaultConfig {
...
resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML"
}
I've dug into the module a bit more and how it works is the native code (Swift/Java) generates header files based on the contents of .env. Changes will not show up until the project is cleaned and re-built. The javascript code simply loads the constants defined in the native level code.
@nlindroos solution is still working and worked for me. I'm using React Native 0.57. I had to manually add the linked library in xcode and everything started working. This, despite the fact that react-native link command all reported back successful.
log: Could not find BuildConfig class. gradle version: 3.3.1 give up usage.
i manage to solve this issue by removing semicolon in the package json
this is the script for package.json in this repo's readme
ENVFILE=".env.staging"; react-native run-ios
this is my package.json script
"android": "ENVFILE=.env.dev react-native run-android"
i hope this help someone
I have created a react native app using create-react-native-app and I have this in my main
app.js
In my constructor I have:
console.log(Config.API_KEY)
And in my
.env
file I have:API_KEY = test
That
Config.API_KEY
appears to be undefined.Is this package supposed to work outside of Android and IOS (that is, straight on
app.js
)?