Answer a question

After reinstalling android studio and vscode I am running into issues with kotlin and gradle. The changes I have made is in root of android folder under build.gradle.

buildscript {
    ext.kotlin_version = '1.5.21 ' //previous was 1.5.20
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.2' // previous was 4.1.1
        classpath 'com.google.gms:google-services:4.3.8'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

I haven't made any other changes, How can I fix this ? The error I get is

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21 .
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.21 /kotlin-gradle-plugin-1.5.21 .pom
       - https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.21 /kotlin-gradle-plugin-1.5.21 .pom
     Required by:
         project :


Answers

The problem you're facing is occurring because you have not added mavenCentral() to your repositories {} block. Add it like this:

repositories {
  mavenCentral()
  google()
}

And also, remove jcenter(), it is deprecated now.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品