android
build_error
ai_generated
true
java.lang.UnsupportedClassVersionError: com/example/MyClass has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java runtime only recognizes class file versions up to 55.0
ID: android/kotlin-unsupported-class-version
92%Fix Rate
86%Confidence
1Evidence
2024-01-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Android Gradle Plugin 7.4.0 | active | — | — | — |
| AGP 8.0.0 | active | — | — | — |
| AGP 8.1.0 | active | — | — | — |
| AGP 8.2.0 | active | — | — | — |
| Kotlin 1.8.0 | active | — | — | — |
| Kotlin 1.9.0 | active | — | — | — |
| Kotlin 2.0.0 | active | — | — | — |
| Java 11 | active | — | — | — |
| Java 17 | active | — | — | — |
| Java 21 | active | — | — | — |
Root Cause
A dependency or project module is compiled with a higher Java bytecode version than the compileSdk or JVM target supports, causing a version mismatch at runtime or build time.
generic中文
依赖项或项目模块使用比 compileSdk 或 JVM 目标支持的更高的 Java 字节码版本编译,导致运行时或构建时版本不匹配。
Official Documentation
https://developer.android.com/studio/build/gradle-tips#configure-jdkWorkarounds
-
90% success Set the Java bytecode version in build.gradle (Module: app): android { compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = "11" } } Ensure the JDK used by Gradle is at least JDK 17 for class file version 61.0. Check with java -version in terminal.
Set the Java bytecode version in build.gradle (Module: app): android { compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = "11" } } Ensure the JDK used by Gradle is at least JDK 17 for class file version 61.0. Check with java -version in terminal. -
92% success If a dependency is compiled with Java 17 bytecode, update the Gradle JDK in Android Studio: File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK > select JDK 17 or higher. Then rebuild.
If a dependency is compiled with Java 17 bytecode, update the Gradle JDK in Android Studio: File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK > select JDK 17 or higher. Then rebuild.
-
85% success Exclude the offending dependency and use a compatible version. For example, if a library requires bytecode 61.0, find an older version that targets 55.0: implementation('com.example:library:1.0.0') { exclude group: 'com.example' } Then add implementation 'com.example:library:0.9.0'.
Exclude the offending dependency and use a compatible version. For example, if a library requires bytecode 61.0, find an older version that targets 55.0: implementation('com.example:library:1.0.0') { exclude group: 'com.example' } Then add implementation 'com.example:library:0.9.0'.
中文步骤
Set the Java bytecode version in build.gradle (Module: app): android { compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = "11" } } Ensure the JDK used by Gradle is at least JDK 17 for class file version 61.0. Check with java -version in terminal.If a dependency is compiled with Java 17 bytecode, update the Gradle JDK in Android Studio: File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK > select JDK 17 or higher. Then rebuild.
Exclude the offending dependency and use a compatible version. For example, if a library requires bytecode 61.0, find an older version that targets 55.0: implementation('com.example:library:1.0.0') { exclude group: 'com.example' } Then add implementation 'com.example:library:0.9.0'.
Dead Ends
Common approaches that don't work:
-
Set compileSdk to a higher value like 34 to force the build to accept newer bytecode
95% fail
compileSdk controls API level, not bytecode version; it does not affect class file version compatibility.
-
Add multiDexEnabled true to build.gradle
99% fail
MultiDex handles method count limits, not bytecode version issues.
-
Downgrade the Kotlin version to 1.6.0 to use older bytecode
80% fail
This may break newer Kotlin features and does not fix the dependency that is already compiled with a higher version.