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

我更新了 Android 工作室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
41502 次浏览

The error is clear Gradle was unable to find the library that you declared

Possible fixes

Location

Project -> build.gradle

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

Edited kotlin has released stable version of version 1.5.0 last night you can use this version to stay up-to-date

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

Worked for me:

Location: build.gradle

change

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

to

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

You should know that there are "two" build.gradle files in the Gradle Scripts on Android Studio, the build.gradle(Project) and build.gradle(Module). It took me hours to realize that I've been looking at the Module version of build.gradle while attempting to fix this and wasn't able to find the proper kotlin version variables to change.

build.gradle(Project) is the proper build.gradle you want to make changes to.

From there change

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

to

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

and try to rebuild your project again. This should work.

On new project create

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

this is work for me

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

Change From

    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"


}
}

Change To

 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"


}
}

Add this dependency into your build.gradle

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

If you want a fast solution, just select 1.4.32 Kotlin version when Android Studio prompt configure Kotlin window.

At this time - May 13, 2021 - selecting 1.5.0 its giving me gradle issues

When ever I started creating a new project this error occurs with the gradle plugin.

UPDATE 14th May 2021 ->

GOTO -> gradle -> build.gradle -> in the code -> dependencies -> Change Classpath -> classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"

and you're good to go.

Please update your Android Studio to 4.2.1(Released on May 13, 2021), the new Stable Version. This issue has been resolved in that:-

Kotlin Issue #187403740: Android Studio 4.2.0 generates projects with the wrong Kotlin version: "1.5.0-release-764"

Change Log

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

New Android Studio 4.2.1 has been released with Patches.

If upgrading does not fix your issues, Try Restart and reset caches.

Otherwise use the solution provided above which is to replace in build.gradle

from

ext.kotlin_version = "1.5.0-release-764"

to

ext.kotlin_version = "1.5.0"

SIMPLEST SOLUTION FOR YOUR PROBLEM:

change :

ext.kotlin_version = "1.5.0-release-764"

to :

ext.kotlin_version = "1.5.0"

in your build.gradle project level

As everybody now knows the solution, we have to get rid of -release-764 as there is no such artifact with this version.

The same can be validated below

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

I just wanted to add a few pointers, whenever you get any such error(Could not resolve all artifacts for any library Could not find xyz) in future for any of the android's library.

Most of the library we use are resolved by

  • google()
  • mavenCentral()

If its a Google's Android library

If it's another android library and you haven't specified any specific repositories for them apart from mavenCentral() then you can use https://mvnrepository.com/ or https://search.maven.org/ to search or validate the version of your library

If in case you are using maven { url 'https://jitpack.io' } as a repository for your library then you can search here https://jitpack.io/.

Hopefully, these pointers will be of any use to someone, this always helps me in case I am getting any such error.

Change the dependency

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

To this

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

If anyone was facing a similar issues for a Java project then Here is a sample build.gradle file (Project Level)

Caution: Notice the mavenCentral() method added there, this is a must to be added for 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
}


In my case this was easily resolved by replacing jcenter() with mavenCentral() in the buildscript and allprojects repositories for build.grade.