Gradle build - failed! (subprocess command not found)

Not sure what happened but recently started getting this error when trying to run my app on an android device from the console

[capacitor] ✖ Running Gradle build - failed!
[capacitor] [error] ERR_SUBPROCESS_COMMAND_NOT_FOUND

This is the command I use:
ionic capacitor run android -l --external

It works fine if I build / run it through Android Studio directly.
Is there anyway to debug this to better understand what is the problem here?

General info:

MacOS 12.3 (21E230) (Intel)
Capacitor v3.4.3
Android Gradle Plugin Version 7.1.2
Gradle Version 7.2
Android SDK Build-Tools from 30.0.2 to 33.0.0-rc2
Android SDK Comman-line Tools 6.0
Android SDK Platform Tools 33.0.1

Ionic info:

Ionic:

Ionic CLI : 6.19.0 (/Users/mindaugas/.config/yarn/global/node_modules/@ionic/cli)
Ionic Framework : @ionic/vue 6.0.13

Capacitor:

Capacitor CLI : 3.4.3
@capacitor/android : 3.4.3
@capacitor/core : 3.4.3
@capacitor/ios : 3.4.3

Utility:

cordova-res : not installed globally
native-run : 1.5.0

System:

NodeJS : v17.8.0 (/usr/local/Cellar/node/17.8.0/bin/node)
npm : 8.5.5
OS : macOS Monterey

Does your environment have a JAVA_HOME variable set? If so, is it JDK 11 or higher? When you build from Android Studio, you won’t have this problem since the IDE will fill it in for you if it’s missing.

It actually wasn’t set but after setting the variable I still get the same error.
I have JDK 12 installed.

This issue has been noted here and here.

So far, it is still unclear what caused this behaviour but for me, the fix (as was noted in Github links) was to force delete node from my system and install it using nodenv.

Also, for JDK it seems that using anything else than JDK 11 will give you other errors that would prevent you from running android builds so it is better to stick with JDK 11.