Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

androidJacocoAnt configuration no longer found with Android Gradle plugin 3.1.0

After updating to Android Gradle plugin 3.1.0 (from 3.0.1) my JaCoCo unit test coverage configuration started producing errors in Gradle config phase:

> Configuration with name 'androidJacocoAnt' not found.

Project-level build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'
    classpath "org.jacoco:org.jacoco.core:0.8.1"
}

Module-level build.gradle:

apply plugin: 'jacoco'

...

android {
    buildTypes {
        debug {
            testCoverageEnabled true
        }
    }

    ...
}

task jacocoTestReport(type: JacocoReport) {
    dependsOn 'createDebugCoverageReport'
    dependsOn 'testDebugUnitTest'

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

    jacocoClasspath = configurations['androidJacocoAnt']

    def fileFilter = [
            '**/R.class',
            '**/R$*.class',
            '**/BuildConfig.*',
            '**/Manifest*.*',
            '**/*Test*.*',
            'android/**/*.*'
    ]

    def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
    def mainSrc = "${project.projectDir}/src/main/java"
    print("${project.projectDir}/src/main/java")

    sourceDirectories = files([mainSrc])
    classDirectories = files([debugTree])
    executionData = fileTree(dir: "$buildDir", includes: [
            "jacoco/testDebugUnitTest.exec",
            "outputs/code-coverage/connected/*coverage.ec"
    ])
}
like image 256
laalto Avatar asked Mar 27 '18 09:03

laalto


People also ask

Where is Android Gradle plugin located?

A Gradle project describes its build in a file called build. gradle located in the root folder of the project.

What is latest Android Gradle version?

7.1.2 (February 2022) Android Gradle Plugin 7.1.

How do I find Gradle plugin version?

In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.

What is Gradle plugin Android?

The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.


2 Answers

Diffing the output of gradle dependencies with different plugin versions, it seems that

jacocoClasspath = configurations['androidJacocoAnt']

needs to change to

jacocoClasspath = configurations['jacocoAnt']
like image 94
laalto Avatar answered Sep 20 '22 10:09

laalto


Do you need JaCoCo 8.1 in latest Android Gradle Plugin 3.1 or higher?

issue is in gradle plugin, in it version of the JaCoCo is hardcoded to 0.7.9

Workaround (step 1 from 2): Add into root build.gradle

buildscript {
    ext {
        jacocoVersion = project.JACOCO_VERSION
    }
    dependencies {
        /* To confirm JaCoCo version run: $ ./gradlew buildEnvironment */
        //region classpath "org.jacoco:org.jacoco.core:${jacocoVersion}"
        /* Resolves issue of incorrect version use in one of jacoco/android plugin inner tasks */
        classpath "org.jacoco:org.jacoco.core:${jacocoVersion}"
        classpath "org.jacoco:org.jacoco.report:${jacocoVersion}"
        classpath "org.jacoco:org.jacoco.agent:${jacocoVersion}"
        //endregion
    }
}

Workaround (step 2 from 2): Add into root build.gradle

/* Force Jacoco Agent version upgrade */
subprojects {
    configurations.all {
        resolutionStrategy {
            eachDependency { details ->
                if ('org.jacoco' == details.requested.group) {
                    details.useVersion "${jacocoVersion}"
                }
            }
        }
    }
}

Enjoy

like image 28
Oleksandr Kucherenko Avatar answered Sep 19 '22 10:09

Oleksandr Kucherenko