Could not find gradle-4.2.1.jar (com.android.tools.build:gradle:4.2.1)

859 Views Asked by At

I have a problem with building project after updating the Android studio to 4.2.1 and the Build Gradle version to 4.2.1. And the gradle version in gradle-wrapper.properties is: distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

Is there any idea to solve this issue?

The error is:

A problem occurred configuring root project Test.
> Could not resolve all artifacts for configuration :classpath.
   > Could not find gradle-4.2.1.jar (com.android.tools.build:gradle:4.2.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.2.1/gradle-4.2.1.jar
   > Could not find builder-4.2.1.jar (com.android.tools.build:builder:4.2.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/4.2.1/builder-4.2.1.jar
   > Could not find bundletool-1.1.0.jar (com.android.tools.build:bundletool:1.1.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/1.1.0/bundletool-1.1.0.jar
   > Could not find protos-27.2.1.jar (com.android.tools.analytics-library:protos:27.2.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/protos/27.2.1/protos-27.2.1.jar

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

-----------------------------------------------------------------------------------------
// project/build.gradle
buildscript {
    ext.kotlin_version = 1.5.0
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath com.android.tools.build:gradle:4.2.1
        classpath org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
2

There are 2 best solutions below

1
On

Change your buildscript from this

repositories {
        google()
        mavenCentral()
    }

Into this

repositories {
       google()
       jcenter()
       mavenCentral()
   }
0
On

I had this problem and solved by update gradle:

from

classpath 'com.android.tools.build:gradle:4.2.1'

to

classpath 'com.android.tools.build:gradle:4.2.2'

update that to latest version.