I'm attempting to run my Ionic application in an Android emulator in Android Studio using the ionic command in terminal in VSCode:
ionic capacitor run android
But I get the following error when running:
[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]
[capacitor] Please set the JAVA_HOME variable in your environment to match the
[capacitor] location of your Java installation.
[capacitor]
So I set the environment variables as seen here:

But I still get the same error?
When I run the java command in the command line that all runs fine:

CodePudding user response:
Java JDK-11 is mostly compatible with android.
- Add correct java path (mostly jre path).
- Run the same command and check again.
CodePudding user response:
maybe you can try to running with Android Studio
ionic cap open android
also you can check the doc https://capacitorjs.com/docs/android/troubleshooting

