If you are trying to run an ionic app with capacitor and you get a similar error message like me, the solution is simple, make sure you follow these steps:

  1. Command: $ npm build
  2. Command: $ ionic cap add android
  3. Command: $ ionic cap open android
  4. Be sure you set your Gradle Java SDK, currently the version that works best is Version 17. See image above
  5. Now you can run your command if you want to: $ ionic cap run android -l --external

This video helped me:

oYvKNTetFJ0

Error message:

Build at: 2024-01-10T04:28:59.383Z - Hash: 08e6970547ca95f0 - Time: 7862ms
> capacitor.cmd run android --target 25e35364c10d7ece
[capacitor] √ Copying web assets from www to android\app\src\main\assets\public in 2.76s
[capacitor] √ Creating capacitor.config.json in android\app\src\main\assets in 5.97ms
[capacitor] [info] Inlining sourcemaps
[capacitor] √ copy android in 2.98s
[capacitor] √ Updating Android plugins in 10.40ms
[capacitor] [info] Found 7 Capacitor plugins for android:
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor] √ update android in 133.86ms
[capacitor] × Running Gradle build - failed!
[capacitor] [error]
[capacitor]         FAILURE: Build failed with an exception.
[capacitor]
[capacitor]         * Where:
[capacitor]         Build file 'G:\xampp8\htdocs\IONIC\REACT\angular-ionic-camera-php\android\build.gradle' line: 18
[capacitor]
[capacitor]         * What went wrong:
[capacitor]         A problem occurred evaluating root project 'android'.
[capacitor]         > Could not open dsl generic class cache for script 'G:\xampp8\htdocs\IONIC\REACT\angular-ionic-camera-php\android\variables.gradle' (C:\Users\15t\.gradle\caches\8.0.2\scripts\eeovjec0aja0v0nqhe47czeq4).
[capacitor]         > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 65
[capacitor]
[capacitor]         * Try:
[capacitor]         > Run with --stacktrace option to get the stack trace.
[capacitor]         > Run with --info or --debug option to get more log output.       
[capacitor]         > Run with --scan to get full insights.
[capacitor]
[capacitor]         * Get more help at https://help.gradle.org
[capacitor]
[capacitor]         BUILD FAILED in 3s
[capacitor]
[ERROR] An error occurred while running subprocess capacitor.

        capacitor.cmd run android --target 25e35364c10d7ece exited with exit code 1.  

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

local.properties file:

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Jan 08 22:54:07 PST 2024
sdk.dir=C\:\\Users\\15t\\AppData\\Local\\Android\\Sdk