106

I updated Android studio 4.2 but I wasn't able to create new project 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
Peter O.
  • 32,158
  • 14
  • 82
  • 96
TEN_KUNG
  • 1,229
  • 2
  • 5
  • 12
  • 13
    remove "-release-764" e.g. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0" – Guy West May 06 '21 at 08:37
  • 8
    But then there is a warning from lint "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)" If the version is bundled with the IDE, how come gradle can't find it? – John Glen May 08 '21 at 15:21
  • 3
    It's fixed in Android Studio 4.2.1: https://androidstudio.googleblog.com/2021/05/android-studio-421-available.html – Martin Marconcini May 14 '21 at 07:25
  • Generic solution to`Could not resolve all artifacts` which will help in future as well too, faced either because of some bug in IDE or mistakenly used wrong artifact version. Do let me know if that helps. https://stackoverflow.com/a/67760444/4828650 – Dinkar Kumar Jun 16 '21 at 01:26

15 Answers15

111

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"
}
Ananiya Jemberu
  • 1,366
  • 1
  • 9
  • 14
  • 3
    Essentially reduce the kotlin-gradle-plugin version from "1.5.0-release-764" to "1.4.30" – Damercy May 05 '21 at 15:23
  • 4
    You can also use "1.5.0" (if you want to use the latest Kotlin version) – Matthew Gharrity May 05 '21 at 17:51
  • 2
    Can I config version by default? Start new project with this version – TEN_KUNG May 06 '21 at 02:42
  • 16
    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 – Mandarin Smell May 06 '21 at 08:24
  • 4
    and don't forget to add `mavenCentral()` if missing – user924 May 06 '21 at 12:23
  • I first tried 1.5.0 and the build succeded. But afterward, when running the emulator, I received other errors. Now I use 1.4.30 and that has finally worked. – cluster1 May 09 '21 at 07:30
  • 1
    Catastrophe. Without StackOverflow one would be lost in such a situation. How is an error like that possible? – cluster1 May 09 '21 at 07:32
  • It was a bug in Android Studio. It's fixed in Android Studio 4.2.1: https://androidstudio.googleblog.com/2021/05/android-studio-421-available.html – Martin Marconcini May 14 '21 at 07:26
  • @michael.zech I have written an answer to give a solution to generic to`Could not resolve all artifacts` which will help in future as well to face either because of some bug in IDE or mistakenly used wrong artifact version. Do let me know if that helps. https://stackoverflow.com/a/67760444/4828650 – Dinkar Kumar Jun 16 '21 at 01:24
64

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()
    }
domi810
  • 641
  • 3
  • 3
24

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.

M.Ed
  • 969
  • 10
  • 12
7

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"
Thiago
  • 12,778
  • 14
  • 93
  • 110
7

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.

Dinkar Kumar
  • 2,175
  • 2
  • 12
  • 22
  • That are definitely useful insights. Thanks a lot. – cluster1 Jun 19 '21 at 06:23
  • @michael.zech glad that you find it useful, if you feel this will help others as well please upvote and show your support. Thanks – Dinkar Kumar Jun 19 '21 at 07:03
  • Well all I had to do was add mavenCentral() in buildscript -> repositories in top level gradle. It couldn't find the appropriate version before. I added mavencentral in allprojects->repositories, but forgot to add it up top. – Vedprakash Wagh Sep 07 '21 at 20:31
7

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"     
    }
Mansi Sharma
  • 965
  • 6
  • 6
6

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()
    }
Jayesh Dankhara
  • 525
  • 7
  • 8
5

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.

Rohit Saka
  • 61
  • 1
4

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"

    }
}
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
sangavi
  • 441
  • 1
  • 3
  • 13
4

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

Nidhin Prathap
  • 696
  • 5
  • 15
2

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

2

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
}

gtxtreme
  • 1,830
  • 1
  • 13
  • 25
1

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

Bink
  • 1,934
  • 1
  • 25
  • 41
0

Add this dependency into your build.gradle

 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50
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

ruif3r
  • 101
  • 2
  • 4