androidcordovagradle

Cordova Android build fails with "Unsupported class file major version 66"


I created a simple Cordova project. I installed Cordova using npm install -g cordova and created my app using cordova create test-project. I changed no configs or anything, just added an h1 in the index.html file.

I want to build the app for android. So I ran cordova platform add android and tried to build it using cordova build android, but this build fails with the following gradle error:

* What went wrong:
BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66
> Unsupported class file major version 66

When I run cordova requirements, it looks like this:

Requirements check results for android:
Java JDK: installed 22.0.0
Android SDK: installed true
Android target: not installed
Command failed with ENOENT: avdmanager list target
spawn avdmanager ENOENT
Gradle: installed /opt/homebrew/Cellar/gradle/8.10.1/bin/gradle

So Android target seems to be missing, but I have no idea how to install it, and on the Platform Guide page for Android in the Cordova docs it's not mentioned. I installed Android SDK version 13 in Android Studio (because in package.json, it says "cordova-android": "^13.0.0"). However that also didn't work.

Any idea why Gradle is failing here? Do I need to install another version of some crap?

Please tell me if you need any other information to help.

Thank you!


Solution

  • I was able to solve the problem by downloading the required JDK for class version 66, which is Java 17, from the Oracle Downloads page.

    I downloaded JDK 17 as a compressed archive into a custom folder I chose and extracted it. Then I set the environment variable JAVA_HOME to the absolute path of the Home directory inside the extracted archive. When I then ran cordova build android again, it worked and created the APK inside platforms/android/app/build/outputs/apk/debug/app-debug.apk.

    Then I sent this APK file to my phone and was (after a security scan) able to install it.