Error: JAVA_HOME is not set and no java command could be found in your PATH docker

Issue

I've followed step by step the official Getting Started. I started from a clean linux install and installed everything required as per the "Building Projects with Native Code" tab. I have also read the troubleshooting section. I've already created the project using the terminal.

This is the error when I run react-native run-android:

Starting JS server... 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: //facebook.github.io/react-native/docs/android-setup.html

It does not find JAVA_HOME because the latest versions of Android Studio don't require Java to be installed in the system. Instead an internal JRE is used.

Duplicate disclaimer: I've already read this question. This is not what I want. I know how to set the Java home. I just want to run the react project WITHOUT having to install a separate Java.

Questions:

  1. How could I find the internal Java inside the Android Studio folder so that I could point JAVA_HOME to it?
  2. If not possible, could I open and run the project inside the android folder with Android Studio? How would I refresh this project after modifying the React JavaScript code in the parent folder?

Solution

I'll answer my own questions and sponfeed my fellow linux users:

1- To point JAVA_HOME to the JRE included with Android Studio first locate the Android Studio installation folder, then find the /jre directory. That directory's full path is what you need to set JAVA_PATH to (thanks to @TentenPonce for his answer). On linux, you can set JAVA_HOME by adding this line to your .bashrc or .bash_profile files:

export JAVA_HOME=<Your Android Studio path here>/jre

This file (one or the other) is the same as the one you added ANDROID_HOME to if you were following the React Native Getting Started for Linux. Both are hidden by default and can be found in your home directory. After adding the line you need to reload the terminal so that it can pick up the new environment variable. So type:

source $HOME/.bash_profile

or

source $HOME/.bashrc

and now you can run react-native run-android in that same terminal. Another option is to restart the OS. Other terminals might work differently.

NOTE: for the project to actually run, you need to start an Android emulator in advance, or have a real device connected. The easiest way is to open an already existing Android Studio project and launch the emulator from there, then close Android Studio.

2- Since what react-native run-android appears to do is just this:

cd android && ./gradlew installDebug

You can actually open the nested android project with Android Studio and run it manually. JS changes can be reloaded if you enable live reload in the emulator. Type CTRL + M (CMD + M on MacOS) and select the "Enable live reload" option in the menu that appears (Kudos to @BKO for his answer)

Answered By - Mister Smith

ERROR: JAVA_HOME is not set and no java command could be found in your PATH in VS code

Questions : ERROR: JAVA_HOME is not set and no java command could be found in your PATH in VS code

2022-08-02T02:15:23+00:00 2022-08-02T02:15:23+00:00

592

I have done android embedding but still I am anycodings_flutter facing this error when I am running my app anycodings_flutter on a physical device. In my laptop Android anycodings_flutter Studio's virtual device does not work and anycodings_flutter sometimes android studio itself so I must anycodings_flutter run it in vs code so please help me out.

Total Answers 0

gradle을 실행하려고하면 다음 오류가 발생합니다.

# gradle ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

그러나 JAVA_HOME 변수를 확인하면 다음과 같은 결과가 나타납니다.

# echo $JAVA_HOME /usr/lib/jvm/java-7-oracle

내 JAVA_HOME은 .bashrc에 정의되어 있으며 소스로 설정되어 있는지 다시 확인했습니다.

java -version또한 Running 은 JAVA_HOME이 올바르게 설정되었으며 PATH에 있는지 확인합니다.

# java -version java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

또한 /usr/bin/java심볼릭 링크가 /etc/alternatives/java올바르게 심볼릭 링크되는지 확인했습니다./usr/lib/jvm/java-7-oracle/jre/bin/java

또한 .bash_profile또는에 중복 된 JAVA_HOME 정의가 없는지 확인했습니다 /etc/profile.

그래서 내 질문은 Gradle이 어떻게 / 왜 찾 /usr/lib/jvm/default-java습니까? 더 중요한 것은 올바른 디렉토리를 어떻게 가리 킵 니까?

JDK가 필요한 다른 프로그램은 제대로 작동하므로 Gradle 문제가 있다고 생각합니다. 또한 차이를 만들지 않은 Gradle을 다시 설치하려고했습니다.

64 비트 Xubuntu (Ubuntu 13.10 기본)를 실행 중입니다.

답변

나는 우분투 13.10 저장소에서 다운로드 한 특정 Gradle을 진 것으로 나타났다 자체는 시도는 JAVA_HOME을 보냅니다. 이것을 제안 해 준 Lucas 에게 감사합니다 .

/usr/bin/gradle 70 행 :

export JAVA_HOME=/usr/lib/jvm/default-java

이 줄을 주석 처리하면 문제가 해결되고 Gradle은 Java 바이너리의 올바른 경로를 찾습니다.

웹 사이트 에서 바이너리를 다운로드하면 이 문제가 발생하지 않으며 Ubuntu repo 버전의 문제입니다. 13.10 버전에는 다른 문제가있는 것 같습니다.

답변

심볼릭 링크 추가

sudo ln -s /usr/lib/jvm/java-7-oracle /usr/lib/jvm/default-java

답변

해결책은 JAVA_HOME == dir을 javac가있는 bin 위에시키는 것입니다.

type javac javac is /usr/bin/javac # now check if its just a symlink ls -la /usr/bin/javac /usr/bin/javac -> /etc/alternatives/javac # its a symlink so check again ls -la /etc/alternatives/javac # now check if its just a symlink /etc/alternatives/javac -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javac

OK 그래서 마침내 실제 javac 위의 저장소를 찾았습니다.

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH

위의 단순화 및 일반화 할 수 있습니다

which javac >/dev/null 2>&1 || die "ERROR: no 'javac' command could be found in your PATH" export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac) )))

답변

나 에게이 오류는 Gradle이 sudo 로 설치되어 Gradle을 실행하기 위해 기본 사용자로 시도한 이유 때문 이었습니다.

시험:

sudo gradle -version

또는

sudo gradle -v

답변

최신 버전을 설치해보십시오 gradle.

sudo add-apt-repository ppa:cwchien/gradle sudo apt-get update sudo apt-get install gradle

우리가 우분투 저장소에서 설치하면 이전 버전이 설치됩니다 (나를 위해 gradle 1.4였습니다). 이전 버전에서는 gradle에서 java 홈을로 설정합니다 export JAVA_HOME=/usr/lib/jvm/default-java. 최신 버전에는이 문제가 없습니다.

답변

당신 export은 JAVA_HOME? 내보내기가 없으면 설정이 해당 셸 내부에서 시작된 명령으로 전파되지 않습니다. 또한를 java -version사용하지 말고 경로에서 JAVA_HOME처음 java찾은 것을 사용합니다 . .bashrc모양이 다음과 같은지 확인하십시오 .

JAVA_HOME=/path/to/java/home export JAVA_HOME

답변

우분투에서 다음 명령을 실행할 때이 문제에 직면했습니다.

ionic build android

이 문제를 해결하기 위해 다음 단계를 수행했습니다.

ln -sf /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java /usr/lib/jvm/default-java

/ etc / environment에 JAVA_HOME을 추가하십시오.

vi /etc/environment

더하다:

JAVA_HOME="/usr/lib/jvm/default-java"

저장 후 다음을 읽으십시오.

source /etc/environment

마지막으로 build 명령을 실행할 수 있습니다.

Toplist

Neuester Beitrag

Stichworte