Gradle build fails: Unable to find method 'org.gradle.api.tasks.testing.Test.getTestClassesDirs()Lorg/gradle/api/file/FileCollection;'

I had to change the distributionUrl in the gradle-wrapper.properties to distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip to get the build running again. This seems to be a similar problem Gradle sync failed: Unable to find method.


If you are getting this error after deleting .gradle and .idea files then the error is happening because the Gradle files are not available for this project and Android studio is unable to download the same version of the Gradle dependency. You can switch to a lower version of the Gradle choose from here and then go to gradle-wrapper-properties file and change the version, in my case I changed it from distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip to distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip. After downloading the older version of the Gradle dependency a Gradle update dialog box would prompt through which you can get the latest version back which is 5.1.1 in this case.


I fix same as this error by add classpath 'com.android.tools.build:gradle:3.2.1' in the build.gradle project

buildscript {

    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

Tags:

Android

Gradle