Unable to build ionic error : Your JAVA\_HOME is invalid: “C:\\Program Files”\\Java\\jdk1.8.0\_291

Issue

I am trying to execute this command

ionic cordova build android --prod --release

and I get the following error :

    Build at: 2021-07-06T09:28:20.394Z - Hash: 933d6e73ee2cc923ca07 - Time: 62511ms
> cordova.cmd build android --release
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOTC:\Users\daees\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOMEC:\Users\daees\AppData\Local\Android\Sdk (DEPRECATED)
Failed to run "javac -version", make sure that you have a JDK version 8 installed.
You can get it from the following location:
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Your JAVA_HOME is invalid: "C:\Program Files"\Java\jdk1.8.0_291
[ERROR] An error occurred while running subprocess cordova.

        cordova.cmd build android --release exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

I tried different solution already discussed but none of them worked for me

Although this says my JAVA_HOME is invalid, but I don’t think so, I have it installed and I’ve added it as environment and System variable

What do I do? Please help

enter image description here

Solution

I simply uninstalled all the versions of JDK and then installed V1.8 again and it worked

Answered By – Sadaf Shafi

Leave a Comment