当前位置:   article > 正文

解决Build failed:Could not resolve com.android.tools.build:gradle:7.4.0-alpha10.

could not resolve com.android.tools.build:gradle:7.4.0.

异常分析

AndroidStudio的项目在build时出现下面的报错:

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘TestApp’.
    Could not resolve all files for configuration ‘:classpath’.
    Could not resolve com.android.tools.build:gradle:7.4.0-alpha10.
    Required by:
    project : > com.android.application:com.android.application.gradle.plugin:7.4.0-alpha10
    project : > com.android.library:com.android.library.gradle.plugin:7.4.0-alpha10
    No matching variant of com.android.tools.build:gradle:7.4.0-alpha10 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-alpha10 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-alpha10 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-alpha10 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-alpha10 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.

在这里插入图片描述
新版本的AndroidStudio出现下面的错误通知:
在这里插入图片描述
此为Android Studio默认的JDK版本与项目配置的Gradle所需的JDK不一致导致冲突所致。要求选择同一版本的JDK。

解决方案

在弹出的错误通知中,选择 Select the Gradle JDK location
在这里插入图片描述
弹出Gradle设置,将默认的JDK改为和项目一样的版本。
在这里插入图片描述
或者进入Preferences->Build,Execution,Deployment->Build Tools->Gradle中,将Gradle user home和项目的Gradle JDK改为一样的版本目录。
在这里插入图片描述

Mac上无法选择 /Applications/Android Studio Preview.app 下的目录,可以直接输入 /Applications/Android Studio Preview.app/Contents/jbr/Contents/Home 在应用程序中的具体地址。
修改的JDK版本按项目要求来设置,有些需要JDK8以上(required compatibility with Java 8)则选择JDK8以上版本。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/89087
推荐阅读
相关标签
  

闽ICP备14008679号