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:

java 复制代码
A problem occurred configuring root project 'starnote'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:7.4.2.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:7.4.2
         project : > com.android.library:com.android.library.gradle.plugin:7.4.2
      > 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:
          - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

二、错误分析

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

java 复制代码
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。

解决方案:

OK->OK->Try Again 齐活。

相关推荐
生产队队长40 分钟前
ThinkPHP:配置Redis并使用
android·数据库·redis
踏雪羽翼43 分钟前
android 差值器的使用
android
Mr-Apple1 小时前
MySQL的Union和OR查询
android·数据库·mysql
yzpyzp1 小时前
如果后台的Long类型的数据返回是null,那么Android客户端的数据bean的kotlin的Long类型的字段接受到数据后是null空指针吗?
android·kotlin
hmywillstronger3 小时前
【Excel】【VBA】根据内容调整打印区域
android·excel
coooliang3 小时前
【Android】ViewPager的使用
android
xvch5 小时前
Kotlin 2.1.0 入门教程(二十五)类型擦除
android·kotlin
simplepeng14 小时前
我的天,我真是和androidx的字体加载杠上了
android
小猫猫猫◍˃ᵕ˂◍15 小时前
备忘录模式:快速恢复原始数据
android·java·备忘录模式
CYRUS_STUDIO17 小时前
使用 AndroidNativeEmu 调用 JNI 函数
android·逆向·汇编语言