How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

androidandroid-studioflutter

I installed Android Studio 4.1 and trying to run existing project. But it gives error like this:

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.

Best Solution

You have to set the JAVA_HOME Environment Variable.

On Windows, I solved the issue as follows:

  1. Download the Java JDK from here and install it. (This links to version 15, which requires you to create an account in order to download. Version 16 is available to download without creating an account, but it has caused me an error that required me to downgrade.)

  2. Set the "JAVA_HOME" Environment Variable:

    • Open Windows Search, type in “env”, and choose “Edit the system environment variables”.

      How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

    • Click on "Environment Variables...".

    • Click on "New".

    • Fill in the "variable name" field with "JAVA_HOME".

    • Fill in the "variable value" with the path to where Java is installed on your computer. (for me it was under "C:\Program Files\Java\<jdkversion>")

      How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

    • Click "OK" and close all dialogs.

  3. Restart your IDE / Terminal. (do not skip this step)

Android Resolver  ERROR: JAVA_HOME ~

Unity에서 Android Resolver를 사용하다 보면 
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. 

라는 에러를 볼 수 있다. JAVA_HOME에 대한 환경변수값이 설정되어 있지 않아서 그런 경우인데 

이럴 경우에는 JAVA_HOME의 환경 변수만 잡아주면 해결이 된다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?
How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

[Edit] -[Preferences]-[External Tools]- JDK의 경로를 Copy Path 한다.

JDK가 설치가 안되어있으면 설치를 진행하면되고 Unity Hub에서는 모듈 설정에서 추가가 가능하다.

[Unity Hub] - [설치] - [모듈 추가] - [Android Build Support]-[OpenJDK]를 설치한다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

JAVA_HOME 환경 변수는 [시스템] - [고급 시스템 설정] -[고급] -[환경변수] 항목에서 추가가 가능하다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

[시스템 변수]-[새로 만들기]를 누르고 변수 이름 "JAVA_HOME" 복사한 JDK 경로를 붙여 넣기 한다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

[시스템 변수]- Path에  %JAVA_HOME%\bin 를 추가한다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

[cmd]- java-version으로 확인한다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

다시 Android Resolver 를 Focus Resolve 해본다. 정상적으로 잘되는 것을 확인할 수 있다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

 ★

Develoment/Unity issue

[유니티] GPGS 플러그인 ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 해결법

Seo_re: 2021. 9. 12. 23:43


※ 해당 에러가나는 유니티 버전은 Hub에서 유니티 설치시, JDK를 같이 설치하는 버전부터이다.


구글 플레이 게임 서비스(이하 GPGS)를 연동하기위해 플러그인을 다운받아 유니티에 임포트를 하고 Resolve를 했는데, 난데없는 에러가 떴다.

Gradle failed to fetch dependencies.
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

'JAVA_HOME'이라는게 설정되지 않았다고한다.

찾아보니 최근 유니티들은 Hub에서 유니티 설치시, SDK, NDK, JDK를 다 설치하다보니 JAVA를 따로 설치할 필요가 없다. 문제는 여기서 발생하는데 GPGS 플러그인 설치 후, Resolve를 할 때 에러가 발생하는것이다.

에러를 추가로 읽어보면,

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

JAVA가 설치된 곳을 JAVA_HOME 변수와 일치시켜달라고 한다. 즉, JAVA_HOME이라는 환경변수를 설정해주면 된다.

그럼 시작해보자!

환경변수 설정

1. 내 컴퓨터에서 속성에 들어간다.

2. 고급 시스템설정 - 환경변수 버튼을 눌러준다.

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

3. 시스템 변수 - 새로 만들기 버튼을 눌러 다음과 같이 설정한다.

4. 변수 값에 OpenJDK의 경로를 넘겨준다

  ※ 경로 : 유니티 설치 경로\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

여기까지 설정을 마쳤다면 이제 재부팅 후 다시 Resolve를 시도해보자!

How do you solve error JAVA_HOME is not set and no Java command could be found in your path?

그러면 Resolve가 진행되며 위와같이 정상적으로 성공 메세지를 받을 수 있다!