Issues with Jacoco Agent in Android Project After Migrating to Kotlin 1.8.20, Java 17, and Gradle 8.0

152 Views Asked by At

I'm currently working on generating a Jacoco report for my Android project. The project is using Kotlin 1.8.20, Java version 17, and Gradle version 8.0. In my build.gradle file, I've added the Jacoco Agent as a dependency using the following classpath: "org.jacoco:org.jacoco.agent:0.8.8".I'm trying to access the Jacoco agent within the JacocoInstrumentation class using Reflection, as shown below:

Object agent = Class.forName("org.jacoco.agent.rt.RT")
    .getMethod("getAgent")
    .invoke(null);

I've attempted this with different versions of Jacoco, ranging from 0.8.8 to 0.8.11. However, I'm consistently encountering the same error. The code was previously working fine when I was using Java version 1.8 and Gradle version 6. After the migration, I'm getting the following error:

java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at package.JacocoInstrumentation.generateCoverageReport(JacocoInstrumentation.java:88)

The error seems to occur at the line Class.forName("org.jacoco.agent.rt.RT"). Can you please provide some insights or guidance on how to resolve this issue?

0

There are 0 best solutions below