Android Studio报错: No matching variant of com.android.tools.build:gradle:7.4.2 was found

一、报错信息

创建个新项目,运行直接报错,信息如下:

No matching variant of com.android.tools.build:gradle:7.4.2 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute ‘org.gradle.plugin.api-version’ with value ‘7.5’ but:

二、错误分析

有些问题是项目中的Gradle版本不是7.4.2,我们需要将build.gradle文件中改它为7.4.2。

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.0' apply false
}

这里明显不是,从报错信息中我们可以看到是Java 版本没跟上,需要将Java 8 改为 Java11。

Solution:

File --> Settings --> Build, Execution, Deployment --> Build Tools --> Gradle
把你的JDK版本切换到11

在这里插入图片描述

如果对你有帮助,就一键三连呗(点赞+收藏+关注),我会持续更新更多干货~~

更多推荐