5

I want to generate code coverage for my project so I have added ,

debug {
      
        testCoverageEnabled true
}

When i run command gradlew createDebugCoverageReport I get the following error

Execution failed for task ':app:createDebugAndroidTestCoverageReport'.

> A failure occurred while executing com.android.build.gradle.internal.coverage.JacocoReportTask$JacocoReportWorkerAction
  
  >Unable to generate Jacoco report

Using same gradle version and kotlin version worked in sample project , Its giving error in my main project .

Manohar
  • 22,116
  • 9
  • 108
  • 144

2 Answers2

8

After a lot of research I found out it was problem with jacoco , Thanks to this issue and its commentors in youtrack which pointed me out in right direction . To fix the issue upgrade the jacoco to version 0.8.7

in app level build.gradle file add these following lines

plugins{
    ...
    id 'jacoco'
}

jacoco {
   toolVersion = "0.8.7"
}

android {
   ...
}

dependencies{
  ...
}

configurations.all{
resolutionStrategy {
    eachDependency { details ->
        if ('org.jacoco' == details.requested.group) {
            details.useVersion "0.8.7"
        }
    }
   }
}

I am not sure why it worked in sample app

Manohar
  • 22,116
  • 9
  • 108
  • 144
2

If in-case, if you use build.gradle.kts

plugins {
    ...
    jacoco
}

jacoco {
    toolVersion = "0.8.7"
}

configurations.all {
    resolutionStrategy {
        eachDependency {
            if (requested.group == "org.jacoco") {
                useVersion("0.8.7")
            }
        }
    }
}

Prashanth Sams
  • 19,677
  • 20
  • 102
  • 125