Reputation: 1
When I try to run command:
react-native run-android
I get this error:
Scanning folders for symlinks in /home/x/myApp/node_modules
(10ms)
JS server already running.
Building and installing the app on the device (cd android &&
./gradlew installDebug)...
ERROR: JAVA_HOME is not set and no 'java' command could be
found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device
connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
JAVA_HOME is set correctly (I think)
java -version
and
echo $JAVA_HOME
return correct results. Screenshot:
JAVA_HOME is set in /etc/environment /etc/profile /bashrc /bash_profile
I did source /bashrc etc too
Virtual device is connected too. I'm able to open this project in android-studio and generate apk
Upvotes: 0
Views: 2097
Reputation: 3676
In linux you don't need to restart your PC, if you have ubuntu or a derivative the file that contains the PATH is in /etc/enviroment , check that file to see if JAVA_HOME is set there.
Aditionally, you might wanna use JDK8 , since JDK9 and 10 don't work well with react native.
Then close your session and login again
Upvotes: 0
Reputation: 689
Make sure you have java installed
after that
if your path is wrong do this:
export | grep JAVA
THE RESULT: what java home is set to
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
follow the path to see if the directories are correct i did this in my terminal:
open /Library
then i went to /Java/JavaVirturalMachines turns out I had the wrong "jdk1.8.0_202.jdk" folder, there was another number... 4. you can use this command to set java_home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
Upvotes: 2