Intro
Unsupported Class File Major Version happens whenever you’re using a JDK which isn’t compatible with the gradle version used in the project.
Solution
This can be easily solved by commonly downgrading to a different version. For libGDX specifically 17 is a good choice. (Or for older projects 8).
If you don’t have a good one installed, I’d recommend to install Bellsofts JDK. The installer has good defaults, and even supports Oracle Specific tools like VisualVM.
Compatibility Matrix
Open gradle/wrapper/gradle-wrapper.properties
in your project to figure out the gradle version (Check the distributionUrl). You can check the compatible JDK version on gradles website.
IntelliJ
There are two steps to fix that in Intellij:
1. Settings
Open File
-> Settings
, then extend Build, Execution, Deployment
-> Build Tools
and click on Gradle
. Change the Gradle JVM
to Project SDK
.
2. Project Structure
Open File
-> Project structure
, then change the SDK
to 11 (or 8). If you don’t want to install a JDK system wide, you can download one in the same drop down.
3. Rebuild the project
Open the Gradle
tab on the right of IntelliJ then click on the Reload All Gradle Projects
button.
After that step the project should work and IntelliJ should setup all the dependencies.
Android Studio
1. Change Gradle Settings
Open the Gradle
tab on the right of Android Studio, then click on the Settings
button and click on Gradle Settings
.
In the newly opened dialog, change the Gradle JDK
to 11 (or 8).
2. Rebuild the project
Click on the Elephant with blue arrow
icon to resync the project.
After that step the project should work and Android Studio should setup all the dependencies.
Eclipse
Import Dialog
I’m not really familiar with eclipse, but it looks like it doesn’t even allow you to import the gradle project when the project throws that error.
So make sure to change Java home
to an appropiate version:
Settings Dialog
If you however managed to open the project somehow, you can change the JDK version under Project
-> Properties
. Then in the dialog select the Gradle
tab and change Java home
there.
After that resync the project by right clicking on the project in the Package Explorer
-> Gradle
-> Refresh Gradle Project
.