gradle Flamingo更新后无法在Android Studio中构建Java或Kotlin项目

6qqygrtg  于 2023-04-30  发布在  Go
关注(0)|答案(1)|浏览(660)

Flamingo更新后无法创建项目,显示一些错误:
没有匹配的 www.example.com :gradle:8.0.0已找到消费者被配置为查找在运行时使用的库,与Java 8兼容,打包为jar,其依赖关系在外部声明,以及属性'org。gradle.plugin.api-version' with value '8.0'

A problem occurred configuring root project 'My Application'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:8.0.0.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:8.0.0
         project : > com.android.library:com.android.library.gradle.plugin:8.0.0
      > No matching variant of com.android.tools.build:gradle:8.0.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.0' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:8.0.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.0')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:8.0.0 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library

我尝试了,但仍然得到这个错误

oxiaedzo

oxiaedzo1#

这是Android Studio的一个bug。新的Android Gradle插件8.0.0现在需要用Java 17执行。如果您从较旧的Android Studio版本升级,通常会配置较旧的Java版本,因此Gradle会失败,并出现您发布的错误。
要使构建过程再次工作,您必须将JDK配置为用于Java 17:
菜单文件-〉设置-〉构建、执行、部署-〉构建工具-〉Gradle -〉Gradle JDK

Android Studio会自动安装相应的Java 17版本jbr-17,因此您只需切换到此Java 17 JDK即可。

相关问题