Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

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

When i am trying to compile a imported project from github, my gradle build always fails with the following exeption.

Unable to find method 'org.gradle.api.tasks.testing.Test.getTestClassesDirs()Lorg/gradle/api/file/FileCollection;'
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes

I followed the instructions given but it didn't work out. Additionally i couldn't get any further information about the error by searching it in the internet

appuild.gradle:

   apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "iammert.com.androidarchitecture"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding {
        enabled = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    /*androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })*/
    //  testCompile 'junit:junit:4.12'

    //support lib
    implementation rootProject.ext.supportLibAppCompat
    implementation rootProject.ext.supportLibDesign

    implementation rootProject.ext.archRuntime
    implementation rootProject.ext.archExtension
    annotationProcessor rootProject.ext.archCompiler

    implementation rootProject.ext.roomRuntime
    annotationProcessor rootProject.ext.roomCompiler

    implementation rootProject.ext.okhttp
    implementation rootProject.ext.retrofit
    implementation rootProject.ext.gsonConverter

    //dagger
    annotationProcessor rootProject.ext.daggerCompiler
    implementation rootProject.ext.dagger
    implementation rootProject.ext.daggerAndroid
    implementation rootProject.ext.daggerAndroidSupport
    annotationProcessor rootProject.ext.daggerAndroidProcessor

    //ui
    implementation rootProject.ext.picasso

}

uild.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

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

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

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

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

ext {
    supportLibVersion = '25.3.1'
    daggerVersion = '2.11'
    retrofitVersion = '2.1.0'
    gsonConverterVersion = '2.1.0'
    okhttpVersion = '3.8.0'
    picassoVersion = '2.5.2'
    archVersion = '1.0.0-alpha1'

    supportLibAppCompat = "com.android.support:appcompat-v7:$supportLibVersion"
    supportLibDesign = "com.android.support:design:$supportLibVersion"
    archRuntime = "android.arch.lifecycle:runtime:$archVersion"
    archExtension = "android.arch.lifecycle:extensions:$archVersion"
    archCompiler = "android.arch.lifecycle:compiler:$archVersion"
    roomRuntime = "android.arch.persistence.room:runtime:$archVersion"
    roomCompiler = "android.arch.persistence.room:compiler:$archVersion"
    dagger = "com.google.dagger:dagger:$daggerVersion"
    daggerCompiler = "com.google.dagger:dagger-compiler:$daggerVersion"
    daggerAndroid = "com.google.dagger:dagger-android:$daggerVersion"
    daggerAndroidSupport = "com.google.dagger:dagger-android-support:$daggerVersion"
    daggerAndroidProcessor = "com.google.dagger:dagger-android-processor:$daggerVersion"
    retrofit = "com.squareup.retrofit2:retrofit:$retrofitVersion"
    gsonConverter = "com.squareup.retrofit2:converter-gson:$gsonConverterVersion"
    okhttp = "com.squareup.okhttp3:okhttp:$okhttpVersion"
    picasso = "com.squareup.picasso:picasso:$picassoVersion"
}

gradlegradle-wrapper.properties:

#Thu May 18 17:31:31 EEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip

Does anyone know why this error occures?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...