I've created the topic in stackoverflow, but even after offering a bounty, not a satisfying reply came actually, so I'm here.
The topic is there: https://stackoverflow.com/questions/55301766/removing-jacoco-library-dependency-while-exporting-project-as-jar
Simply what I have and what I'm trying to do is:
- We have an SDK project written on Android, started to use Jacoco a few months ago, and after that time everytime we export the project as .jar, whether we set the "testCoverageEnabled" true or not, it's causing crash on the app that uses our .jar file as a library.
The crash is:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_8ff85ea/Offline;
Which is kinda popular crash when implementing to the project, but for an sdk project it is weird, as of course jacoco dependency shouldn't be in the library somehow.
So is there a possibility to exclude jacoco dependencies while exporting the application?
implementation is something like that: (I've tried with adding additional classpath for offline solution and also with the jacoco version of 0.8.3)
gradle:
classpath 'org.jacoco:org.jacoco.core:0.8.1'
jacoco {
toolVersion = '0.8.1'
}
//this adds robolectric tests to coverage report
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testProductionDebugUnitTest',
'createProductionDebugCoverageReport']) {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
html.setDestination(new File("$project.buildDir/reports/jacoco/html"))
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*',
'android/**/*.*']
def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/production/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: project.buildDir, includes: ['**/*.exec', '**/*.ec'])
}
Thanks in advance!
Also try to follow the answers on SO. They look very reasonable to me.
Android Plugin for Gradle, when instructed to measure coverage using JaCoCo, uses offline instrumentation and therefore requires two types of build - with coverage and without for release.
whether we set the "testCoverageEnabled" true or not