更新到AndroidStudio4.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"
}

  • I know we can just use 1.5.0, but Android Studio warns us that we have to use 1.5.0-release-764 while this versions seems not deployed, or not able to be gotten from 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) `. I remember I had same warning before as well too, and I could *avoid* warning with same solution like this time

  • You can also use "1.5.0" (if you want to use the latest Kotlin version)
  • and don't forget to add `mavenCentral()` if missing
  • Essentially reduce the kotlin-gradle-plugin version from "1.5.0-release-764" to "1.4.30"
  • Can I config version by default? Start new project with this version

回答

为我工作:

位置:build.gradle

改变

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

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

  • Just to add more explicit detail, be sure to make the changes `build.grade (Project: <app_name>)` file

回答

您应该知道 Android Studio 上的 Gradle 脚本中有“两个”build.gradle 文件,即 build.gradle(Project) 和 build.gradle(Module)。我花了几个小时才意识到我一直在查看 build.gradle 的模块版本,同时试图解决这个问题,但无法找到合适的 kotlin 版本变量进行更改。

build.gradle(Project) 是您要对其进行更改的正确 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()
    }


回答

由于现在每个人都知道解决方案,我们必须摆脱,-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 库

  • 搜索 google 的 maven repo https://maven.google.com/以查看您要查找的版本是否正确,或者是否存在最新版本的库。
  • google 的 android 库在 mavenCentral 中仍然可用的很少,您可以使用https://mvnrepository.com/或https://search.maven.org/来搜索或验证您的库的版本

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

如果您将其maven { url 'https://jitpack.io' }用作库的存储库,则可以在此处搜索https://jitpack.io/。

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


回答

改变依赖

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


以上是更新到AndroidStudio4.2后无法创建新的Kotlin项目的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>