You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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(推荐)

  1. 打开Android Studio,进入「File」>「Project Structure」>「Project」
  2. 在「Gradle JDK」下拉菜单中选择「JDK 17」,若本地无该版本,点击「Download JDK」自动下载安装
  3. 点击「OK」保存配置,重新执行构建

方案二:降级AGP和Gradle适配JDK 11

若暂时无法升级JDK,可将AGP和Gradle降级至支持JDK 11的版本:

  1. 修改项目级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
    }
    
  2. 修改gradle-wrapper.properties的Gradle版本为7.5(适配AGP 7.4.2):
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
    
  3. 点击「Sync Now」同步项目,重新执行构建

内容的提问来源于stack exchange,提问作者Andrew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 05:36:08