Unsupported class file major version 66


I have seen many folks having similar issues - i.e., Java not playing nice with Gradle - alas most seem related to the compatibility matrix not being taken into account.

I believe that my setup SHOULD work, as 8.8 was announced to be compatible with Java 22, but something still ain’t right. Any suggestions welcome.

Note that this is the first time ever that I installed Gradle, Android Studio and Cordova.

Gradle 8.8

Build time:   2024-05-31 21:46:56 UTC
Revision:     4bd1b3d3fc3f31db5a26eecb416a165b8cc36082

Kotlin:       1.9.22
Groovy:       3.0.21
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          22.0.1 (Oracle Corporation 22.0.1+8-16)
OS:           Windows 11 10.0 amd64

FAILURE: Build failed with an exception.

* 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

You are most probably looking at different things.

You said you installed Gradle, which usually is an error in itself. Every project should have the four Gradle Wrapper files included or imho has a build bug. These files define which Gradle version the build is run with and and care about auto-provisioning and using it. An installed Gradle version you only need if you have a project that misses the wrapper files, or want to bootstrap a new Gradle build without another one at hand and without an IDE that ships Gradle

So if your first output was from your installed Gradle version, that’s fine. But if your second output was from trying to execute a build, you installed Gradle version is irrelevant.

Hello Björn, thanks for your insights!

Based on this, I did more digging and voilà - figured out that my Android Studio/Cordova installation seems to be stuck with Gradle 8.7. after project setup, ignoring my JDK version of 22 which should have triggered the use of compatible version 8.8. - if I read your comment correctly.

I then set out to update the wrapper manually, as explained here, alas the action failed. I first had to downgrade my JDK to 21, as outlined here. NOW the upgrade to 8.8 worked just fine and the build compiled without error. Same goes for upgrading back to JDK 22 - the build compiles.

My key findings would be: The wrapper, at least the one in Android Studio, behaves not as clever as we assumed.

In addition, please note that I had to also install Gradle itself since Android Studio no longer comes with a working binary, compare here.

And Cordova explicitly says in their documentation to install it, explaining that the “[…] system’s Gradle binary will create the Gradle Wrapper file that declares and obtains the appropriate version of Gradle needed for building the Android application. The system-level and project-level version of Gradle may not and does not need to match. The project-level’s version of Gradle is defined in the Cordova-Android’s package and set based on what Android supports.”

Thanks again for your support. Maybe this conversation will be valuable for other Seekers of Knowledge. Cheers!

Ah, I see.
So a bug (imho, or call it design flaw, whatever you prefer) of Cordova (whatever that is) requires you to install Gradle in the system, I see.
Smells like poorly designed integration.
They should for example simply use the tooling API to drive a Gradle build and not shell out to a system-installed Gradle.

But :man_shrugging: