2

I have following setup

  • AGP 7.x+
  • Kotlin 1.5.x+
  • JaCoCo 0.8.7+
  • Java 11 set as the JDK
  • Java 1.8 set as jvmTarget and compileOptions

but when trying to run the AndroidTest and generate jacoco report, it fails with

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_3570298/Offline;

After doing my research it seems I need to add jacocoagent.jar to classpath, but how?

Tried adding testImplementation 'org.jacoco:org.jacoco.agent:0.8.7' and also downloading jar file from search.maven.org/artifact/org.jacoco/org.jacoco.agent/0.8.7/jar and adding jacoco-agent.properties file referencing the jar but no success :/ what am I missing...

(things I've looked into:

Removing Jacoco library dependency while exporting project as jar

how to prevent jacoco instrumenting production code?

https://issuetracker.google.com/issues/37116868 )

Anhee
  • 21
  • 3

1 Answers1

0

You need to use the correct classifier in the artifact coordinates in order to directly reference the jacocoagent.jar:

 [group: 'org.jacoco', name: 'org.jacoco.agent', classifier: 'runtime',
 version: "$JACOCO_VERSION"]

As in:

configurations {
    ...
    jacocoAgent
    ... }

dependencies {
    ...
    jacocoAgent ([group: 'org.jacoco', name: 'org.jacoco.agent', classifier: 'runtime', version: "..."],)
    ... }
Sweta Jain
  • 3,248
  • 6
  • 30
  • 50
iliyan
  • 1
  • 2