Error: Failed to run "javac -version", make sure that you have a JDK Installed
Asked Answered
H

4

13

Error: Failed to run "javac -version", make sure that you have a JDK installed. You can get it from: http://www.oracle.com/technetwork/java/javase/downloads. Your JAVA_HOME is invalid: C:\Program Files\Java\jdk1.8.0_152;

[ERROR] An error occurred while running cordova run android (exit code 1)

My JAVA_HOME : C:\Program Files\Java\jdk1.8.0_152;C:\Program Files\Java\jdk1.8.0_152\bin;

ANDROID_HOME: C:\Users\Felipe\AppData\Local\Android\sdk;

Path: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%JAVA_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\nodejs\;C:\apache-ant-1.9.6\bin;%JAVA_HOME%;C:\Users\Felipe\AppData\Local\Android\sdk\build-tools\27.0.0;C:\Users\Felipe\AppData\Local\Android\sdk\tools;

Any idea why returns me this error when i try to use ionic cordova run android?

Havildar answered 31/10, 2017 at 16:53 Comment(3)
JAVA_HOME should contain just one entry, pointing to the root directory of the JRE/JDK. In your case, JAVA_HOME should be C:\Program Files\Java\jdk1.8.0_152Croaky
Thank you! Works...Havildar
I had this error randomly appear after building for Apache Cordova targeting my physical android device. Disconnecting and reconnecting the physical device annoyingly fixed the issue :/Melodramatic
D
17

Search for "edit environment variables" in start. and under user variables add a new variable with name "JAVA_HOME" and value with path_to_jdk_bin.

like this

enter image description here

Now under system variables, the path variable should contain(add if not added) the entry %JAVA_HOME%.

Like this

enter image description here

Dickie answered 31/10, 2017 at 17:7 Comment(2)
JAVA_HOME should not include the bin directory, just the JDK root folder.Shackle
In order for it to work for me, I had to include the bin folder in the path and not just the root folder as @Shackle addressed.Moquette
M
3

Firstly make sure you don't have multiple java versions installed

Once you're done with that open Environment Variables tab under My computers

Create a new user variable and name it PATH

Set the user variable value as C:\Program Files\Java\jdk1.8.0_151\bin(may change depending on where you have installed java)

open cmd type javac

This should be enough to make it work

Marasco answered 9/1, 2018 at 10:29 Comment(0)
H
1

I've been trying to figure this out and just found a solution I haven't seen elsewhere.

I noticed I had a second version of Java installed in my Program Files (x86) directory.

Pointing the variables to that location instead, ie C:\Program Files (x86)\Java\jdk1.8.0_131 and now everything works fine.

Hassiehassin answered 11/6, 2018 at 19:18 Comment(0)
F
0

Try This:

In VS, open Tools menu and select Options.

In Tools for Apache Cordova select Environment Variable Overrides .

Select JAVA_HOME checkbox and browse for JDK directory.

Cordova Environment Variable Overrides

Fante answered 11/9, 2019 at 4:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.