jacocoTestReport task not being generated

ant2009 picture ant2009 · Jan 27, 2018 · Viewed 9.6k times · Source
Android Studio 3.1 Canary 8
Build #AI-173.4529993, built on January 6, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.14.14-300.fc27.x86_64

I am trying to use the jacoco to generate code coverage. However, when I run the command ./gradlew tasks I don't see any tasks called jacocoTestReport.

I get the below error when I try and run the tasks ./gradlew jacocoTestReport:

Task 'jacocoTestReport' not found in root project 'EnumSample'

This is my build.gradlew file:

apply plugin: 'com.android.application'
apply plugin: 'jacoco'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "me.androidbox.enumsample"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
        }
    }
}

jacoco {
    toolVersion "0.8.0"
}

task jacocoTestReport(type: JacocoReport) {
    executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")

    subprojects.each {
        sourceSets it.sourceSets.main
    }

    reports {
        xml.enabled true
        html.enabled false
        csv.enabled false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

I have tried to clean and rebuild the project. However, the reporting task isn't there.

Many thanks for any suggestions.

Answer

azizbekian picture azizbekian · Feb 13, 2018

You are searching for a wrong task to execute. By performing ./gradlew tasks you'll be able to find createFlavorCoverageReport tasks:

enter image description here

After executing ./gradlew createDevDebugCoverageReport with the setup that you have mentioned in the question I was able to find generated report at /app/build/reports/dev/debug directory.