Home > OS >  Could not find gradle-7.0.3.jar
Could not find gradle-7.0.3.jar

Time:02-18

When I want to run my application I get the following error:

> Could not find gradle-7.0.3.jar (com.android.tools.build:gradle:7.0.3).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.0.3/gradle-7.0.3.jar

so I tried to edit build.gradle and replace com.android.tools.build:gradle:4.1.0 with com.android.tools.build:gradle:7.0.3

but I still get this error.

CodePudding user response:

if you changed com.android.tools.build:gradle:4.1.0 with com.android.tools.build:gradle:7.0.3 you also need to change in the same file this : ext.kotlin_version = '1.6.10'

find the kotlin version for your gradle version .

for example gradle:4.1.0 works with kotlin_version = 1.6.10

CodePudding user response:

From the documentation at https://developer.android.com/studio/releases/gradle-plugin#updating-gradle , you need to add the gradle plugin classpath to your project build.gradle at projectName/android/build.gradle. And you also need to add google maven google() for the repositories.

See the following example of project build.gradle:

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

and you also need upgrading the gradle binary to version >= 7.0 like the documentation says

You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or by editing the Gradle distribution reference in the gradle/wrapper/gradle-wrapper.properties file. The following example sets the Gradle version to 7.0.0 in the gradle-wrapper.properties file.

Go to projectName/android/gradle/wrapper and modified gradle-wrapper.properties so it becomes like the following (Remember to change the version to 7.0 ):

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
  • Related