【问题标题】:Can't create new Kotlin project after updating to Android Studio 4.2更新到 Android Studio 4.2 后无法创建新的 Kotlin 项目
【发布时间】:2021-07-27 16:49:16
【问题描述】:

我更新了 Android Studio 4.2,但我无法创建新项目 kotlin

A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0-release-764.
 Searched in the following locations:
   - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.0-release- 
764/kotlin-gradle-plugin-1.5.0-release-764.pom
   - https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.0-release-764/kotlin-gradle-plugin-1.5.0-release-764.pom
 Required by:
     project :

Possible solution:
- Declare repository providing the artifact, see the documentation at 
 https://docs.gradle.org/current/userguide/declaring_repositories.html

【问题讨论】:

  • 删除“-release-764”例如类路径“org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0”
  • 但是 lint 发出警告“用于使用 Gradle (1.5.0) 构建的 Kotlin 版本与捆绑到 IDE 插件 (1.5.0-release-764) 中的版本不同”如果版本是捆绑IDE的,gradle怎么找不到呢?
  • 已在 Android Studio 4.2.1 中修复:androidstudio.googleblog.com/2021/05/…
  • Could not resolve all artifacts 的通用解决方案在将来也会有所帮助,因为 IDE 中的一些错误或错误地使用了错误的工件版本。如果有帮助,请告诉我。 stackoverflow.com/a/67760444/4828650

标签: android android-studio kotlin android-studio-4.2


【解决方案1】:

错误很明显 Gradle 无法找到您声明的库

可能的修复

位置

项目 -> build.gradle

//update it
dependencies {
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
}

已编辑 kotlin 昨晚发布了 1.5.0 版的稳定版,您可以使用此版本保持最新状态

dependencies {
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
}

【讨论】:

  • 基本上将 kotlin-gradle-plugin 版本从“1.5.0-release-764”减少到“1.4.30”
  • 你也可以使用“1.5.0”(如果你想使用最新的Kotlin版本)
  • 我可以默认配置版本吗?使用此版本启动新项目
  • 我知道我们可以只使用 1.5.0,但是 Android Studio 警告我们必须使用 1.5.0-release-764,而这个版本似乎没有部署,或者无法从 maven 获得. Kotlin version that is used for building with Gradle (1.5.0) differs from the one bundled into the IDE plugin (1.5.0-release-764) 。我记得我之前也收到过同样的警告,我可以避免使用像这次一样的解决方案发出警告
  • 如果缺少请不要忘记添加mavenCentral()
【解决方案2】:

为我工作:

位置:build.gradle

改变

buildscript {
    ext.kotlin_version = "1.5.0-release-764"
    repositories {
        google()
        mavenCentral()
    }

buildscript {
    ext.kotlin_version = "1.5.0"
    repositories {
        google()
        mavenCentral()
    }

【讨论】:

  • 只是为了添加更明确的细节,请务必更改build.grade (Project: <app_name>)文件
【解决方案3】:

您应该知道,Android Studio 上的 Gradle 脚本中有“两个”build.gradle 文件,即 build.gradle(Project) 和 build.gradle(Module)。我花了几个小时才意识到,在尝试修复此问题时,我一直在查看 build.gradle 的模块版本,但无法找到要更改的正确 kotlin 版本变量。

build.gradle(Project) 是您要更改的the proper build.gradle

从那里改变

buildscript {
ext.kotlin_version = "1.5.0-release-764"
repositories {
    google()
    mavenCentral()
}

buildscript {
ext.kotlin_version = "1.5.0"
repositories {
    google()
    mavenCentral()
}

并尝试再次重建您的项目。这应该可以。

【讨论】:

    【解决方案4】:

    创建新项目

    buildscript {        ext.kotlin_version = "1.5.0-release-764"
            repositories {
                google()
                mavenCentral()
            }
    

    这对我有用

    buildscript {
        ext.kotlin_version = "1.4.30"
        repositories {
            google()
            mavenCentral()
        }
    

    【讨论】:

      【解决方案5】:

      更改自

          buildscript {
          ext.kotlin_version = "1.5.0-release-764" //Remove release-764
          repositories {
              google()
              mavenCentral()
          }
          dependencies {
              classpath "com.android.tools.build:gradle:4.2.0"
              classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      
          }
      }
      

      更改为

       buildscript {
          ext.kotlin_version = "1.5.0" //Here is the change have to add this Version 
          repositories {
              google()
              mavenCentral()
          }
          dependencies {
              classpath "com.android.tools.build:gradle:4.2.0"
              classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      
          }
      }
      

      【讨论】:

        【解决方案6】:

        将此依赖项添加到您的 build.gradle 中

         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
        

        【讨论】:

          【解决方案7】:

          如果您想要快速解决方案,只需在 Android Studio 提示配置 Kotlin 窗口时选择 1.4.32 Kotlin 版本即可。

          此时 - 2021 年 5 月 13 日 - 选择 1.5.0 它给了我 gradle 问题

          【讨论】:

            【解决方案8】:

            当我开始创建一个新项目时,会出现此错误 gradle 插件。

            更新2021 年 5 月 14 日 ->

            GOTO -> gradle -> build.gradle -> 在代码中 -> 依赖项 -> 更改 Classpath -> classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0”

            你可以走了。

            【讨论】:

              【解决方案9】:

              请将您的 Android Studio 更新至 4.2.1(2021 年 5 月 13 日发布),即新的稳定版。 这个问题已经解决了:-

              Kotlin 问题 #187403740:Android Studio 4.2.0 生成的项目使用了错误的 Kotlin 版本:“1.5.0-release-764”

              更改日志

              https://androidstudio.googleblog.com/2021/05/android-studio-421-available.html

              【讨论】:

                【解决方案10】:

                新的 Android Studio 4.2.1 已随补丁一起发布。

                如果升级无法解决您的问题,请尝试重新启动并重置缓存。

                否则使用上面提供的解决方案,即在 build.gradle 中替换

                来自

                ext.kotlin_version = "1.5.0-release-764"
                

                ext.kotlin_version = "1.5.0"
                

                【讨论】:

                  【解决方案11】:

                  为您的问题提供最简单的解决方案:

                  改变:

                  ext.kotlin_version = "1.5.0-release-764"

                  到:

                  ext.kotlin_version = "1.5.0"

                  在您的 build.gradle 项目级别

                  【讨论】:

                    【解决方案12】:

                    由于现在每个人都知道解决方案,我们必须摆脱-release-764,因为这个版本没有这样的工件。

                    下面也可以验证

                    https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin

                    我只是想添加一些指针,每当您将来遇到任何此类错误时(Could not resolve all artifacts 对于任何库 Could not find xyz)对于任何 android 的库。

                    我们使用的大部分库都是由

                    解析的
                    • google()
                    • mavenCentral()

                    如果它是 Google 的 Android 库

                    如果它是另一个 android 库,并且除了 mavenCentral() 之外,您还没有为它们指定任何特定的存储库,那么您可以使用 https://mvnrepository.com/https://search.maven.org/ 来搜索或验证您的库的版本

                    如果您使用 maven { url 'https://jitpack.io' } 作为库的存储库,那么您可以在此处搜索 https://jitpack.io/

                    希望这些指针对某人有用,如果我遇到任何此类错误,这总是对我有帮助。

                    【讨论】:

                    • 这绝对是有用的见解。非常感谢。
                    • @michael.zech 很高兴您发现它有用,如果您觉得这对其他人也有帮助,请点赞并表示支持。谢谢
                    • 好吧,我所要做的就是在 buildscript -> 顶级 gradle 的存储库中添加 mavenCentral()。之前找不到合适的版本。我在 allprojects->repositories 中添加了 mavencentral,但忘记将其添加到顶部。
                    【解决方案13】:

                    改变依赖

                    ext.kotlin_version = "1.5.0-release-764"
                       dependencies {
                           classpath "com.android.tools.build:gradle:4.2.0"
                           classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
                       }
                    

                    到这里

                    ext.kotlin_version = "1.5.10"
                        dependencies {
                            classpath "com.android.tools.build:gradle:4.2.1"
                            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"     
                        }
                    

                    【讨论】:

                    • 一旦 Android Studio 从 4.2 版更新到 4.2.1 版,就成功了,谢谢!
                    【解决方案14】:

                    如果有人在 Java 项目中遇到类似问题,那么 这是一个示例build.gradle 文件(项目级别)

                    注意:注意那里添加了mavenCentral()方法,这是必须为gradle添加4.2.1+

                    buildscript {
                        repositories {
                            google()
                            mavenCentral()
                        }
                        dependencies {
                            classpath 'com.google.gms:google-services:4.3.8'
                            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.0'
                            classpath 'com.android.tools.build:gradle:4.2.1'
                        }
                    }
                    
                    
                    allprojects {
                        repositories {
                    
                    
                            mavenCentral()
                            maven {
                                url "https://maven.google.com/"
                            }
                    
                            google()
                    
                            maven() {
                                url "https://oss.sonatype.org/content/repositories/snapshots"
                            }
                    
                            jcenter()
                    
                            maven { url 'https://jitpack.io' }
                    
                    
                        }
                    }
                    
                    task clean(type: Delete) {
                        delete rootProject.buildDir
                    }
                    
                    

                    【讨论】:

                      【解决方案15】:

                      在我的情况下,这很容易解决,方法是在 buildscript 和 allprojects 存储库中将 jcenter() 替换为 build.grade 中的 mavenCentral()。

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 2015-07-24
                        • 2019-04-17
                        • 1970-01-01
                        相关资源
                        最近更新 更多