文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Android Studio 解决Could not resolve com.android.tools.build:gradle:7.4.2问题

2023-09-14 16:05

关注

A problem occurred configuring root project 'MyApplication2'.

> 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')

      昨天用老版本的Android Studio 新建了一个Kotlin项目,. 之类的提示没有,应该是环境问题,就升级了Android Studio到最新的电鳗版本,新建kotlin项目就报上述错误。

      搜索了一圈,原来是gradle插件7.4.2版本比较新,需要Java11,以前配置的是Java8,修改下配置就可以了,以mac电脑为例,操作如下:

左上角 File ------- Project Structure, 如图:

 2、SDK Location -----------  Gradle Settings ,如图:

 3、Gradle JDK, 选择11的,点击OK , 如图:

 4、Settings.gradle文件里,配置一些仓库地址,如图:

 代码如下:

pluginManagement {    repositories {        maven { url 'https://maven.aliyun.com/repository/releases' }        maven { url 'https://maven.aliyun.com/repository/public' }        maven { url 'https://maven.aliyun.com/repository/jcenter' }        maven { url 'https://maven.aliyun.com/repository/google' }        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }        maven { url "https://www.jitpack.io" }        google()        mavenCentral()        gradlePluginPortal()        jcenter()    }}dependencyResolutionManagement {    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)    repositories {        maven { url 'https://maven.aliyun.com/repository/releases' }        maven { url 'https://maven.aliyun.com/repository/public' }        maven { url 'https://maven.aliyun.com/repository/jcenter' }        maven { url 'https://maven.aliyun.com/repository/google' }        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }        maven { url "https://www.jitpack.io" }        google()        mavenCentral()        jcenter()    }}rootProject.name = "MyApplication2"include ':app'

 5、点击同步按钮,下载相应的库,如图:

等待下载完毕,可能需要几分钟到几十分钟,只要下载进度是对的,就OK,如图:

. 已经可以正常提示语法了

好了,又可以愉快的玩耍了。

来源地址:https://blog.csdn.net/msn465780/article/details/129981203

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-移动开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯