"ionic cap run android --livereload --external" not working

Here is the error:

capacitor.cmd run android --no-sync --target ZY22H2NXDQ
[capacitor] × Running Gradle build - failed!
[capacitor] [error]
[capacitor] ERROR: JAVA_HOME is not set and no ‘java’ command could be found in your PATH.
[capacitor] Please set the JAVA_HOME variable in your environment to match the
[capacitor] location of your Java installation.
[ERROR] An error occurred while running subprocess capacitor…

My JAVA_HOME var is set to: C:\Program Files (x86)\Common Files\Oracle\Java\javapath

Any ideas what is causing this error? Or how to troubleshoot it?

Hi msbednar, I have the same problem! Have you been able to solve it?

I was able to get it to work, but unfortunaley I don’t know what I did to fix it. I did several things including:

Changing the JAVA_HOME environment variable (caused the Androild Stuio emulator to stop working)

Reinstalled the Java SDK

Reinstalled Android Studio

The emulator still would not work so I installed an older verion of the Emulator into Android Studio.

I tried again and the command worked. I wish I could provide more help but I don’t know why it started to work.