Android Studio构建报错:Java Runtime版本不兼容问题求助
Android构建版本兼容性问题修复方案
错误日志
An exception occurred applying plugin request [id: 'com.android.application'] > Failed to apply plugin 'com.android.internal.application'. > Could not create an instance of type com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated. > Could not create an instance of type com.android.build.gradle.internal.dsl.LintImpl$AgpDecorated. > Could not generate a decorated class for type LintImpl$AgpDecorated. > com/android/tools/lint/model/LintModelSeverity 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
当前环境配置
- Gradle版本:gradle-8.0(来自
gradle-wrapper.properties)distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists - AGP版本:8.1.1(来自项目级
build.gradle)plugins { id 'com.android.application' version '8.1.1' apply false id 'com.android.library' version '8.1.1' apply false id 'org.jetbrains.kotlin.android' version '1.8.20' apply false } - 当前JDK版本:JDK 11.0.13
修复步骤
错误核心是AGP 8.1.1依赖JDK 17(class file version 61.0),但当前使用的JDK 11仅支持最高class file version 55.0,同时Gradle版本也需和AGP、JDK版本匹配,可任选以下两种方案:
方案一:升级JDK到17(推荐)
- 打开Android Studio,进入「File」>「Project Structure」>「Project」
- 在「Gradle JDK」下拉菜单中选择「JDK 17」,若本地无该版本,点击「Download JDK」自动下载安装
- 点击「OK」保存配置,重新执行构建
方案二:降级AGP和Gradle适配JDK 11
若暂时无法升级JDK,可将AGP和Gradle降级至支持JDK 11的版本:
- 修改项目级
build.gradle的AGP版本为7.4.2(兼容JDK 11的最高AGP版本):plugins { id 'com.android.application' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false id 'org.jetbrains.kotlin.android' version '1.8.20' apply false } - 修改
gradle-wrapper.properties的Gradle版本为7.5(适配AGP 7.4.2):distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip - 点击「Sync Now」同步项目,重新执行构建
内容的提问来源于stack exchange,提问作者Andrew
相关产品推荐
相关产品推荐

