TEN_KUNG
TEN_KUNG

Reputation: 1229

Can't create new Kotlin project after updating to Android Studio 4.2

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

Upvotes: 106

Views: 49085

Answers (15)

Bink
Bink

Reputation: 2171

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

Upvotes: 1

gtxtreme
gtxtreme

Reputation: 3576

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
}

Upvotes: 2

Mansi Sharma
Mansi Sharma

Reputation: 995

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

Upvotes: 7

Dinkar Kumar
Dinkar Kumar

Reputation: 2250

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.

Upvotes: 7

Ratik Tiwari
Ratik Tiwari

Reputation: 21

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

Upvotes: 2

Thiago
Thiago

Reputation: 13302

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"

Upvotes: 7

Nidhin Prathap
Nidhin Prathap

Reputation: 722

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

Upvotes: 4

Rohit Saka
Rohit Saka

Reputation: 61

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.

Upvotes: 5

ruif3r
ruif3r

Reputation: 121

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

Upvotes: 0

Pankaj kumar
Pankaj kumar

Reputation: 1

Add this dependency into your build.gradle

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

Upvotes: 0

sangavi
sangavi

Reputation: 441

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"

    }
}

Upvotes: 4

Jayesh Dankhara
Jayesh Dankhara

Reputation: 839

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()
    }

Upvotes: 6

M.Ed
M.Ed

Reputation: 1328

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.

Upvotes: 24

Ananiya J. Kesto
Ananiya J. Kesto

Reputation: 1364

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

Upvotes: 111

domi810
domi810

Reputation: 641

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()
    }

Upvotes: 64

Related Questions