When you open a project in Android Studio or run Gradle Sync or a build,
an error called
“Unsupported class file major version”
may be displayed.
This error occurs when the JDK version that created a Java class file
is incompatible with the environment, such as Gradle or the JDK,
that is trying to read that class file.
It may occur especially when the JDK is updated,
when Android Studio or Gradle is updated,
or when an old Android project is opened in a newer Java environment.
This article explains the main causes and solutions for
“Unsupported class file major version” in Android Studio.
- What Is “Unsupported class file major version”?
- Main Causes
- Check the major version in the Error Message
- Check the Correspondence Between major version and Java Version
- Check the Java Version Currently Being Used
- Check the Gradle JDK
- Check the JDK Bundled with Android Studio
- Check the Gradle Version
- Check the Current Gradle Version
- If the JDK Is Too New
- If Gradle Is Too Old
- Check the Android Gradle Plugin Version
- Check the Combination of Gradle and the Android Gradle Plugin
- If It Occurred After Updating Android Studio
- If Only the JDK Was Updated
- If Only Gradle Was Updated
- When Opening an Old Project with a Newer JDK
- If an External Plugin Is the Cause
- If a Dependency Library Is the Cause
- Do Not Confuse the System Java with the Gradle JDK
- Check JAVA_HOME
- Run Gradle Sync Again
- Run Clean Project
- Restart Android Studio
- What to Check for Each Error
- Steps to Check If the Problem Is Not Resolved
- Summary
What Is “Unsupported class file major version”?
“Unsupported class file major version” is an error displayed
when the current Java runtime environment, Gradle, or another component
cannot read the version of a Java class file.
A
.class
file compiled with Java contains a major version
corresponding to the Java version that was used.
For example,
if a class file created with a newer JDK is read by an older Gradle or JDK
that does not support it,
this error may occur.
Point:
“Unsupported class file major version” may not be a problem with Android Studio itself,
but may instead be caused by the combination of versions of
JDK, Gradle, Android Gradle Plugin, and other components.
Main Causes
The main causes of
“Unsupported class file major version”
in Android Studio include the following.
- The JDK being used is too new
- The Gradle version is old
- The Android Gradle Plugin version is old
- A JDK that is not supported by the Gradle JDK is selected
- The JDK changed after updating Android Studio
- Only the JDK was updated
- Only Gradle was left at an old version
- An old Android project was opened with a newer JDK
- An external plugin was compiled with a newer Java version
- The system Java and Android Studio’s Gradle JDK are different
Check the major version in the Error Message
The error may display a major version number as follows.
Unsupported class file major version 65
The major version number corresponds to the Java version.
For example,
major version 65 indicates a class file generated with Java 21.
Therefore,
if the Gradle or Java environment reading this class file does not support Java 21,
the error may occur.
Check the Correspondence Between major version and Java Version
The correspondence between commonly used major versions and Java versions
is as follows.
| major version | Java Version |
|---|---|
| 52 | Java 8 |
| 55 | Java 11 |
| 61 | Java 17 |
| 62 | Java 18 |
| 63 | Java 19 |
| 64 | Java 20 |
| 65 | Java 21 |
From the major version displayed in the error,
you can check which Java version was used to create the class file.
Check the Java Version Currently Being Used
You can check the Java version currently being used
from Terminal or another command-line environment.
java -version
The displayed Java version is not necessarily the same as
the JDK actually used by Gradle in Android Studio.
Therefore,
you also need to check the Gradle JDK on the Android Studio side.
Check the Gradle JDK
Android Studio allows you to configure the JDK used by Gradle separately.
Even if the correct JDK is displayed by the system’s
java -version,
a different Gradle JDK may be selected in Android Studio.
Open the Gradle settings in Android Studio
and check the currently selected Gradle JDK.
Select a JDK supported by the Gradle and Android Gradle Plugin you are using.
Check the JDK Bundled with Android Studio
Android Studio may include a bundled JDK.
Using the JDK bundled with Android Studio as the Gradle JDK
may reduce problems caused by version differences
from Java installed externally.
However,
you need to check whether the Gradle and Android Gradle Plugin being used
support that JDK.
Check the Gradle Version
If the JDK is new,
an older Gradle version may not be able to use that Java version.
The Gradle version used by the project
can normally be checked in the following file.
gradle/wrapper/gradle-wrapper.properties
Check the
distributionUrl
in the file.
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
Check the Current Gradle Version
You can use the Gradle Wrapper from Terminal
to check the version of Gradle currently being used.
./gradlew --version
On Windows,
depending on the environment,
run the following.
gradlew.bat --version
This output lets you check not only the Gradle version,
but also information about the JVM used by Gradle.
If the JDK Is Too New
If the JDK being used is too new for Gradle,
“Unsupported class file major version” may occur.
In this case,
update Gradle to a version that supports the newer JDK,
or change the JDK being used to a version supported by Gradle.
Which one should be changed
should be determined while also considering compatibility
with the Android Gradle Plugin and other components.
If Gradle Is Too Old
If you are using a newer JDK
while the Gradle Wrapper is old,
Gradle may not be able to handle the newer Java class file format.
In this case,
check the Gradle version in
gradle-wrapper.properties
and change it to a Gradle version that supports the JDK being used.
Note:
If you update only Gradle to the latest version,
a compatibility problem with the Android Gradle Plugin may occur.
Also check the compatibility between Gradle and the Android Gradle Plugin.
Check the Android Gradle Plugin Version
The Android Gradle Plugin also has compatibility relationships
with Gradle and JDK.
Depending on the project,
the Android Gradle Plugin version may be specified as follows.
plugins {
id("com.android.application") version "8.5.0" apply false
}
In older project formats,
it may be configured as follows.
classpath 'com.android.tools.build:gradle:8.5.0'
If the Android Gradle Plugin is old,
it may not support combinations with newer Gradle or JDK versions.
Check the Combination of Gradle and the Android Gradle Plugin
When “Unsupported class file major version” occurs,
changing only the JDK does not necessarily resolve the problem.
In an Android project,
the three versions of
Android Gradle Plugin,
Gradle,
and JDK
are related.
If only one of them is changed significantly,
another compatibility error may occur.
Therefore,
make changes while checking the compatibility among all three.
If It Occurred After Updating Android Studio
When Android Studio is updated,
the JDK used by Gradle
or the recommended Android Gradle Plugin version may change.
If “Unsupported class file major version” started occurring
immediately after updating Android Studio,
check whether the Gradle JDK has changed from what was previously used.
Also check whether the Gradle used by the project
supports the newly selected JDK.
If Only the JDK Was Updated
If only the JDK was updated to a newer version,
an older Gradle may not support the newer Java version,
causing an error.
If the error occurred immediately after updating the JDK,
check the Gradle Wrapper version.
If necessary,
update Gradle
or return to the JDK that was previously used.
If Only Gradle Was Updated
Even if only Gradle is updated,
another compatibility error may occur
depending on the combination with the Android Gradle Plugin and JDK.
If the error occurred immediately after updating Gradle,
also check the Android Gradle Plugin and JDK versions.
When Opening an Old Project with a Newer JDK
In an old Android project,
the Gradle and Android Gradle Plugin versions from that time are being used.
If that project is opened with a newer Android Studio or JDK,
the old Gradle may not support the newer Java environment.
In this case,
while checking the compatibility among
Gradle,
Android Gradle Plugin,
and JDK,
update the necessary components in order.
If an External Plugin Is the Cause
A Gradle plugin other than the Android Gradle Plugin
may also have been compiled with a newer Java version.
If that plugin is loaded by an older JDK or Gradle,
“Unsupported class file major version” may occur.
If a specific plugin name is displayed before or after the error,
also check the Java and Gradle versions required by that plugin.
If a Dependency Library Is the Cause
Class files included in an external library or dependency
may have been created with a newer Java version
than the current environment.
If a specific JAR file or library name is displayed in the error,
check the Java version supported by that library.
Do Not Confuse the System Java with the Gradle JDK
If multiple JDKs are installed on the PC,
the Java used in Terminal
and the Java used by Gradle in Android Studio may be different.
In Terminal,
you can check the Java version with the following command.
java -version
On the other hand,
the JVM actually used by Gradle
can also be checked with the following command.
./gradlew --version
These two commands may display different Java versions.
Check JAVA_HOME
If you run Gradle from the command line,
the
JAVA_HOME
setting may also affect the result.
If
JAVA_HOME
points to an old JDK or an unintended JDK,
Gradle may run in a different Java environment from Android Studio.
If the results differ between running from Android Studio and running from Terminal,
also check
JAVA_HOME.
Run Gradle Sync Again
After changing the JDK,
Gradle,
or Android Gradle Plugin settings,
run Gradle Sync again.
Run
Sync Project with Gradle Files
or a similar option from Android Studio.
Even if the previous error remains after changing the settings,
the new settings may be loaded through Sync.
Run Clean Project
Even after changing the JDK or Gradle,
previous build artifacts may remain.
Run
Clean Project
from the Build menu or another location in Android Studio,
and then run Gradle Sync or Rebuild Project.
Restart Android Studio
If the previous state remains
even after changing the Gradle JDK or other settings,
restart Android Studio.
After restarting,
run Gradle Sync
and check whether the new JDK and Gradle settings are being used.
What to Check for Each Error
Depending on the Java- or Gradle-related error,
you can narrow down what should be checked to some extent.
| Displayed Message | Main Points to Check |
|---|---|
| Unsupported class file major version | JDK, Gradle, Android Gradle Plugin |
| Minimum supported Gradle version is … | Gradle Wrapper, Android Gradle Plugin |
| incompatible version of the Android Gradle plugin | Android Studio, Android Gradle Plugin, Gradle |
| Unsupported Java | JDK, Gradle |
| Gradle sync failed | Detailed error, compatibility among JDK, Gradle, and plugins |
Steps to Check If the Problem Is Not Resolved
If you do not know the cause,
checking the following in order makes it easier to narrow down the problem.
- Check the full “Unsupported class file major version” error message
- Check the major version displayed in the error
- Check the Java version corresponding to the major version
- Check the system Java with
java -version - Check the Gradle JDK in Android Studio
- Check Gradle and the JVM with
./gradlew --version - Check the Gradle version in
gradle-wrapper.properties - Check the Android Gradle Plugin version
- Check the compatibility among JDK, Gradle, and the Android Gradle Plugin
- Change the JDK or Gradle to a compatible version if necessary
- Check whether an external plugin or library is the cause
- Check
JAVA_HOMEif necessary - Run Gradle Sync again
- Run Clean Project if necessary
- Restart Android Studio if necessary
Important:
If “Unsupported class file major version” is displayed,
rather than simply making the JDK newer or older,
it is important to check the compatibility among
JDK, Gradle, and the Android Gradle Plugin
and use a supported combination.
Summary
Android Studio’s
“Unsupported class file major version”
is an error displayed when the Java class file version
is incompatible with the JDK, Gradle, or other component reading it.
It may occur especially when only the JDK is updated,
when an older Gradle is used in a newer Java environment,
or when an old Android project is opened in a newer Android Studio.
First, check the major version displayed in the error,
and then use
java -version
and
./gradlew --version
to check the Java and Gradle versions actually being used.
Then,
check the Gradle JDK in Android Studio,
the Gradle Wrapper,
and the Android Gradle Plugin version,
change them to a compatible combination,
and run Gradle Sync again
to efficiently narrow down the cause.
