# java.lang.UnsupportedClassVersionError：com/example/MyClass 由较新版本的 Java 运行时编译（类文件版本 61.0），此 Java 运行时版本仅识别最高 55.0 的类文件版本

- **ID:** `android/kotlin-unsupported-class-version`
- **领域:** android
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

依赖项或项目模块使用比 compileSdk 或 JVM 目标支持的更高的 Java 字节码版本编译，导致运行时或构建时版本不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 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 | — | — |

## 解决方案

1. ```
   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.
   ```
2. ```
   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.
   ```
3. ```
   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 compileSdk to a higher value like 34 to force the build to accept newer bytecode** — compileSdk controls API level, not bytecode version; it does not affect class file version compatibility. (95% 失败率)
- **Add multiDexEnabled true to build.gradle** — MultiDex handles method count limits, not bytecode version issues. (99% 失败率)
- **Downgrade the Kotlin version to 1.6.0 to use older bytecode** — This may break newer Kotlin features and does not fix the dependency that is already compiled with a higher version. (80% 失败率)
