I am new to the react native.
I am using a linux machine
. I am trying to run an application.
Now, Here what I have done ,
I already have java installed in my machine .So, that time I have added,
in my profile
I have following env variables .
export JAVA_HOME='/usr/local/java'
export PATH=$PATH:$HOME/bin:$JAVA_HOME/jdk1.8.0_121/bin
Now, after that I have installed the android studio
in my one of folders,
which is /home/softwares/android-studio
.
That time I have added the env variables in the profile file.which are
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
Now, my project folder is like ,
/home/projectWork/native/app
Added the script in the package.json file , but there
it is giving me this error .
JS server not recognized, continuing with build...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
ERROR: JAVA_HOME is set to an invalid directory: /usr/local/java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Now, I am not getting a way to resolve this issue . Can any one help me with this ?
I am new to the react native.
I am using a linux machine
. I am trying to run an application.
Now, Here what I have done ,
I already have java installed in my machine .So, that time I have added,
in my profile
I have following env variables .
export JAVA_HOME='/usr/local/java'
export PATH=$PATH:$HOME/bin:$JAVA_HOME/jdk1.8.0_121/bin
Now, after that I have installed the android studio
in my one of folders,
which is /home/softwares/android-studio
.
That time I have added the env variables in the profile file.which are
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
Now, my project folder is like ,
/home/projectWork/native/app
Added the script in the package.json file , but there
it is giving me this error .
JS server not recognized, continuing with build...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
ERROR: JAVA_HOME is set to an invalid directory: /usr/local/java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Now, I am not getting a way to resolve this issue . Can any one help me with this ?
Share Improve this question asked Dec 8, 2018 at 9:25 ganesh kaspateganesh kaspate 2,69512 gold badges52 silver badges105 bronze badges 2-
1
The JAVA_HOME variable is pointing to the wrong directory it should be
/usr/local/java/jdk1.8.0_121
– Edwardth Commented Dec 8, 2018 at 9:34 - what about the JS server not recognized, continuing with build... is that okay ? – ganesh kaspate Commented Dec 8, 2018 at 9:37
4 Answers
Reset to default 1Set the java home in MacOs Monterey 1 Set up JAVA_HOME in environment variable 1.1 Open your shell profile file for editing using a text editor like nano or vim. You can use the nano editor as an example: nano ~/.zshrc # For Zsh. // Run that mand in your Zsh terminal
2 Add the following line to set the JAVA_HOME variable to the correct Java installation path. Make sure to replace the path with the one you mentioned in your output: export JAVA_HOME=/Library/Java/JavaVirtualMachines/Your JDK Version/Contents/Home.
3 Save the file and exit the text editor. In nano, you can do this by pressing Ctrl + O to write changes, then Enter to confirm the file name, and finally Ctrl + X to exit. 4 Source the profile file to apply the changes to your current terminal session. >>> source ~/.zshrc # For Zsh //Run that mand in your terminal 5 Verify that the JAVA_HOME variable has been set correctly by running echo $JAVA_HOME. //Run that mand in your terminal
6 Finally, try running your React Native project again: npx react-native run-android
**
This should resolve the "JAVA_HOME is set to an invalid directory" error, and React Native should be able to use the correct Java installation for building your Android project.
**
I think you need to set your JAVA_HOME
to the actual JDK:
export JAVA_HOME='/usr/local/java/jdk1.8.0_121'
For windows user that is downgrading from JDK 17 to JDK 8, you need to ensure a few things:
- Set the java home and path correctly.
- Remove JDK 17 folder from program files path.
You just need to set the JAVA_HOME in your Environemnt. For Linux users. check these solutions: How to set JAVA_HOME in Linux for all users