未找到 com.android.tools.build:gradle:7.4.0 的匹配变体

Jun*_*ncu 133 android android-studio

我刚刚创建了一个全新的 Material 3 compose 项目,然后弹出以下内容:

> No matching variant of com.android.tools.build:gradle:7.4.0 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.0 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.0 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.0 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.0 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')
Run Code Online (Sandbox Code Playgroud)

没有改变任何东西,一切都是默认的。

Jun*_*ncu 274

最终将 Gradle JDK 更改为 11。

File-> Settings-> Build, Execution, Deployment-> Build Tools->Gradle

  • 请注意,在 macOS 上,设置位于“Android Studio”菜单下。我这里只是选择了“Embedded JDK”,也就是Android Studio捆绑的JDK。 (6认同)
  • 电鳗很奇怪。首先我在一个 Flutter 项目中遇到了这个:/sf/ask/3589719171/#comment132597544_75119315 然后现在在一个 Android 项目中这似乎是也有可能是JDK版本的问题。为什么要重置这些? (5认同)
  • 这太疯狂了!我也有这个问题。 (5认同)
  • 尝试在 github actions 上运行 `reactivecircus/android-emulator-runner@v2` 时遇到了这个问题。在运行模拟器运行程序之前添加“actions/setup-java@v3”并将 JDK 设置为 11 解决了该问题。 (4认同)

qui*_*uin 39

对于 Mac 用户(正如 @Frederik 指出的那样),“设置”是“首选项”: 偏好设置位置

进而:
在此输入图像描述
精加工:
在此输入图像描述


cho*_*nge 16

如果在 Kotlin Multiplatform (KMM) 上升级到 Java 17。

当您创建新的 KMM 项目时,Android Studio 的 Gradle 构建设置自动默认为Java 1.8(或为 JAVA_HOME 或 org.gradle.java.jome 指定的任何内容)。

如果您升级到Android Java 11Studio,Java 13它将成功构建并在 Android Studio 上运行,但不会在 Xcode 上成功构建或运行。

解决方法(似乎)是再升级一个版本Java 17(在我的例子中是亚马逊的 corretto-17)

科雷托-17

使用低于 17 的版本似乎破坏了 Xcode 中预期的 Gradle 插件版本(但仅限于 Xcode)——这会引入文件夹的范围问题shared


使用 CocoaPods 和常规框架创建新项目时进行了测试。

Android Studio Flamingo并排测试Xcode version 14.3


小智 10

需要做两步...

将 Gradle JDK 更改为 11。

文件 -> 设置 -> 构建、执行、部署 -> 构建工具 -> Gradle

然后

文件 -> 修复 IDE。执行每个步骤,直到重新启动,然后开始下载大量文件。此后构建工作。