• 【错误记录】Android Studio 创建 Module 模块报错 ( Cannot resolve external dependency org.jetbrains.kotlin:kotl )



    目前使用的是 最新的 Gradle 配置 , 创建 Module 生成的源码与 Gradle 配置出现了冲突 , 导致的问题 ;

    解决此类问题 , 要仔细检查 Gradle 构建脚本 , 排查每个依赖库的来源 ;

    本次错误就是 AS 系统自动成的 Module 修改了 Gradle 构建脚本 , 导致依赖下载失败 ;





    一、报错信息



    在 Android Studio 的 已存在 工程中 , 创建 新的 Module 模块应用 , 在重新编译时报如下错误 ;

    之前的应用 编译运行 正常 , 创建了新 Module 模块后 , 出现如下错误 ;

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    A problem occurred configuring root project 'Navigation'.
    > Could not resolve all files for configuration ':classpath'.
       > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0-RC2 because no repositories are defined.
         Required by:
             project :
    
    * Try:
    > Run with --info or --debug option to get more log output.
    > Run with --scan to get full insights.
    
    * Exception is:
    org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'Navigation'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    在这里插入图片描述





    二、解决方案



    没有找到依赖 , 基本就是 依赖库 没有配全 , 配置一个 Maven 仓库源齐全的配置 , 一般配置

    • Maven 中央仓库 : mavenCentral() , 重要的依赖库一般都有 ;
    • Google 仓库 : google() , 谷歌的仓库 , 可能会被墙 ;
    • Jcenter 仓库 : jcenter() , 虽然已经停止运营 , 但是之前的库还能下载 ;
    • 阿里云仓库 : 两个 阿里云 的 仓库 , 可以快速下载对应的依赖 ;
            maven {
                url 'https://maven.aliyun.com/repository/public/'
            }
            maven{
                url 'https://maven.aliyun.com/repository/google/'
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    一般的 Maven 源配置如下 : 使用如下配置 , 很少出现下载依赖库失败的情况 ;

        repositories {
            google()
            mavenCentral()
            jcenter()
            maven {
                url 'https://maven.aliyun.com/repository/public/'
            }
            maven{
                url 'https://maven.aliyun.com/repository/google/'
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    添加了新的 Maven 源之后 , 还是报错 , 再次检查了下发现 我导入的 Kotlin 插件版本是 org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20 , 并不是报错中的 org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0-RC2 版本 ;

    在这里插入图片描述

    检查了所有的 Gradle 构建脚本 , 发现创建 Module 时 , 被 Android Studio 插入了如下配置 :

    buildscript {
        dependencies {
            classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0-RC2'
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    插入了插件配置 , 但是没有给配置 Maven 源 , 这才导致了无法下载该 Kotlin 依赖 ;

    这里直接将该配置删除即可 , 不能同时配置两个 Kotlin 依赖 ;
    在这里插入图片描述

    如果 不删除 上述插件配置 , 给 该 buildscript 配置添加 repositories 的 Maven 源 , 是可以编译通过的 ;

    buildscript {
        repositories {
            google()
            mavenCentral()
            jcenter()
            maven {
                url 'https://maven.aliyun.com/repository/public/'
            }
            maven{
                url 'https://maven.aliyun.com/repository/google/'
            }
        }
        dependencies {
            classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0-RC2'
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
  • 相关阅读:
    基于matlab的长短期神经网络lstm的股票预测
    Mysql 45讲学习笔记(三十三)全表扫描为啥不会OOM(out of memory)
    Git ignore、exclude for TortoiseGit 小结
    多路复用IO与NIO
    springboot调用第三方接口json转换成对象
    【Prometheus】Prometheus 集群与高可用
    MySQL 约束
    ViT结构详解(pytorch代码)
    开设自己的网站系类03安装数据库(centos版)
    秋招每日一题T5——校庆
  • 原文地址:https://blog.csdn.net/han1202012/article/details/132564358