I'm trying to set up Cordova. When I run cordova build android
I receive the following error:
(node:6816) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 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_161;C:\Program Files\Java\jdk1.8.0_161\bin
However I can run javac -version
just fine.
C:\>javac -version
javac 1.8.0_161
I've tried to set JAVA_HOME
in various ways: pointing to the root; pointing to the bin
folder; set it as a User variable and also a System one; add %JAVA_HOME%\bin
to Path
(both for User and System) and so on.
I've checked several articles about this issue, and they say that if I'm able to use javac -version
then that's supposed to indicate that my environmental variables are set correctly. Even if that's the case, Cordova still doesn't seem to recognize it.
Following Stephen C's instructions, I've reset my variables, yet my error still persists. As you can see in the image I can call javac
just fine, and both JAVA_HOME
and Path
seem to be set in the right way. (Note that actually it is %JAVA_HOME%\bin
and not C:\Program Files\Java\jdk1.8.0_161\bin
in the Path
.)
I think you are confusing JAVA_HOME, PATH and CLASSPATH
The JAVA_HOME variable should be set to the name of a single directory. Not multiple directories with separators. The JAVA_HOME directory is the top directory of your JDK or JRE installation. Not the "bin" directory.
The PATH and CLASSPATH variables consist of a list of paths. For PATH the paths are pathnames for directories. For CLASSPATH the paths are pathnames for directories or JAR / ZIP files (or a particular kind of wildcard).
The PATH is where the shell searches for commands if you use a command name that is a simple name; e.g. java
or javac
.
`
Your error message says this:
Your JAVA_HOME is invalid:
C:\Program Files\Java\jdk1.8.0_161;C:\Program Files\Java\jdk1.8.0_161\bin
This is wrong for two reasons:
The other thing you may have gotten wrong is that changes to environment variables do not necessarily propagate. For example, if you start a shell and then change an environment variable via the Windows GUI, the change may not propagate to the shell. You may need to exit the shell and restart it to pick up the new value.
If you are unsure, you can run (for example) echo %PATH%
to see the current value of PATH
in the current shell or script.
UPDATE
According to http://cordova.apache.org/docs/en/7.x/guide/platforms/android/index.html, you need to:
ANDROID_HOME
environment variable to the location of your Android SDK installation. It is also recommended that you add the Android SDK's tools, tools/bin, and platform-tools directories to your PATH
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With