Error: java_home is not set and no java command could be found in your path. vs code

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

오류 해결 방법. 

유니티를 2019 이상 버전 사용 시 이전 버전의 유니티와는 다르게 JDK를 허브를 통해서 설치하기 때문에 

따로 JAVA를 설치 할 필요가 없습니다. 

덕분에 생기는 문제인데 저의 경우에는 구글 플레이 서비스(GPGS)를 사용하기 위해 플러그인 설치 시 

Resolving Android Dependencies 에서 오류가 발생했습니다. 

Error: java_home is not set and no java command could be found in your path. vs code
Error: java_home is not set and no java command could be found in your path. vs code
Error: java_home is not set and no java command could be found in your path. vs code

위와 같은 오류가 발생합니다. 

문제는 자바를 설치한적이 없으니 JAVA_HOME 환경 설정이 된적이 없다는 겁니다. 

해결 방법은 컴퓨터에 유니티 설치 시 같이 설치한 JDK의 경로를 JAVA_HOME 이라는 이름으로 환경 설정을 추가해 주면 됩니다. 

방법은 아래와 같습니다. (윈도우 기준)

1. 먼저 자신의 유니티 에디터에 설치된 JDK 경로를 확인 합니다. 

ex) C:\Program Files\2019.2.18f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\OpenJDK\Windows

2. 내 컴퓨터에서 마우스 오른쪽 클릭 -> 속성 클릭 하여 시스템 창을 열어줍니다. 

Error: java_home is not set and no java command could be found in your path. vs code

3. 시스템창에서 왼쪽 메뉴에 고급 시스템 설정 클릭 

Error: java_home is not set and no java command could be found in your path. vs code

4. 시스템 속성에서 환경 변수 클릭 

Error: java_home is not set and no java command could be found in your path. vs code

5. 새로 만들기 클릭 (만약 기존에 JAVA_HOME이 있다면 편집으로 경로만 변경해줘도 됩니다.)

Error: java_home is not set and no java command could be found in your path. vs code

6. 변수 이름에 JAVA_HOME , 변수 값에 아까 위에서 확인한 경로를 입력합니다. 

Error: java_home is not set and no java command could be found in your path. vs code

7. 환경 변수가 만들어 졌으면 컴퓨터를 리부팅 합니다. 새로 만들거나 편집한 환경 변수를 리부팅을 해야지만 적용됩니다. 

8. 유니티로 돌아와서 Play Services Resolver -> Android Resolver -> Force Resolve

Error: java_home is not set and no java command could be found in your path. vs code

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. 고급 시스템설정 - 환경변수 버튼을 눌러준다.

Error: java_home is not set and no java command could be found in your path. vs code

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

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

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

Error: java_home is not set and no java command could be found in your path. vs code

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

Error: java_home is not set and no java command could be found in your path. vs code

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