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


    异常分析

    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以上版本。

  • 相关阅读:
    军队文职丨2022年武警部队面向社会公开招聘351名文职人员公告!高中学历可报,11月25日前报名!
    Netty服务端开发及性能优化
    论文解读(GCC)《Efficient Graph Convolution for Joint Node RepresentationLearning and Clustering》
    TCP SYNCookie机制
    人机杂感
    如何使用 FastAPI 部署 NLP 模型?
    2023谷歌开发者大会直播详细脚本
    第五章第一节:树与二叉树
    Linux-Docker-Rabbitmq安装
    gflags学习笔记(一)gflags的介绍和安装(ubuntu环境)
  • 原文地址:https://blog.csdn.net/CJohn1994/article/details/126882187