Can't create new Kotlin project after updating to Android Studio 4.2
AndroidAndroid StudioKotlinAndroid Studio-4.2Android Problem Overview
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
Android Solutions
Solution 1 - Android
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"
}
Solution 2 - Android
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()
}
Solution 3 - Android
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.
Solution 4 - Android
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"
Solution 5 - Android
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
- Search google's maven repo https://maven.google.com/ to see if the version you are looking for is even the correct one or what is the latest version of the library exists.
- Few of the google's android library is still available at mavenCentral, you can use https://mvnrepository.com/ or https://search.maven.org/ to search or validate the version of your 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.
Solution 6 - Android
>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"
}
Solution 7 - Android
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()
}
Solution 8 - Android
> 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.
Solution 9 - Android
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"
}
}
Solution 10 - Android
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
Solution 11 - Android
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
Solution 12 - Android
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
}
Solution 13 - Android
Add this dependency into your build.gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
Solution 14 - Android
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
Solution 15 - Android
In my case this was easily resolved by replacing jcenter() with mavenCentral() in the buildscript and allprojects repositories for build.grade.