微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更新到 Android Studio 4.2 后无法创建新的 Kotlin 项目

如何解决更新到 Android Studio 4.2 后无法创建新的 Kotlin 项目

我更新了 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

解决方法

错误很明显 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"
}
,

为我工作:

位置:build.gradle

改变

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

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

你应该知道在Android Studio的Gradle Scripts中有“两个”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()
}

并尝试再次重建您的项目。这应该有效。

,

新的 Android Studio 4.2.1 已发布补丁。

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

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

来自

ext.kotlin_version = "1.5.0-release-764"

ext.kotlin_version = "1.5.0"
,

在创建新项目时

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

这对我有用

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

改变依赖

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"     
    }
,

现在大家都知道解决方案了,我们必须去掉-release-764,因为这个版本没有这样的工件。

同样可以在下面验证

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

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

我们使用的大部分库都由

解析
  • google()
  • mavenCentral()

如果是 Google 的 Android 库

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

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

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

,

当我开始创建一个新项目时,这个错误发生在 gradle 插件。

更新 2021 年 5 月 14 日 ->

GOTO -> gradle -> build.gradle -> 代码中 -> 依赖 -> 更改类路径 -> classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"

一切顺利。

,

请将您的 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

,

更改自

    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"

    }
}
,

解决您问题的最简单方法:

改变:

ext.kotlin_version = "1.5.0-release-764"

到:

ext.kotlin_version = "1.5.0"

在您的 build.gradle 项目级别

,

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

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

如果想快速解决,Android Studio 提示配置 Kotlin 窗口时选择 1.4.32 Kotlin 版本即可。

此时 - 2021 年 5 月 13 日 - 选择 1.5.0 会给我带来 gradle 问题

,

如果有人在 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
}

,

在我的情况下,通过在 buildscript 和 build.grade 的所有项目存储库中将 jcenter() 替换为 mavenCentral() 可以轻松解决此问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。