jacoco / jacoco/jacoco

Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter (conflict with fabric)

Open
#639 9 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback pending help wanted :vulcan_salute:
Dominant language
Java
Stars
4.6k
Forks
1.2k
Avg merge
1d 9h
Merged PRs (30d)
23

Description

JaCoCo version: 0.8.0
Operating system: Linux
Tool integration: Android gradle

I'm running into an issue in an android project, after updating from jacoco 0.7.9 to 0.8.0.
Not sure if this should be reported here, or somewhere else... Starting here since it works fine with 0.7.9.

When running ./gradlew clean assembleDebug:

Expected behaviour

The command completes without error, producing an apk.

Actual behaviour

I get the below exception:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter
        at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:88)
        at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:108)
        at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:135)
        at com.android.build.gradle.internal.transforms.JacocoTransform.instrumentFile(JacocoTransform.java:172)
        at com.android.build.gradle.internal.transforms.JacocoTransform.instrumentFilesFullRun(JacocoTransform.java:160)
        at com.android.build.gradle.internal.transforms.JacocoTransform.transform(JacocoTransform.java:119)
        at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:185)
        at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:181)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
        at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:176)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:179)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:135)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:122)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)

I should note that I have updated two other android projects to use jacoco 0.8.0, and they seem to work fine. I haven't yet identified what's different in this project. (more info below)

I've integrated jacoco as follows:

root build.gradle file:

buildscript {
     dependencies {
         classpath 'com.android.tools.build:gradle:3.0.1'
         classpath 'org.jacoco:org.jacoco.core:0.8.0'
    }
}

app module build.gradle file:

apply plugin: 'jacoco'
android {
    buildTypes {
        debug {
            testCoverageEnabled = true
        }
    }
    testOptions {
        unitTests {
            all {
                jacoco {
                    // We need to set includeNoLocationClasses or robolectric tests won't be counted:
                    // https://stackoverflow.com/questions/35735085/jacoco-doesnt-work-with-robolectric-tests
                    includeNoLocationClasses = true
                }
        }
    }
}
jacoco {
    toolVersion '0.8.0'
}
/** other config for configuring the jaoco report, but I think it's irrelevant for this bug which occurs earlier, in `assembleDebug` **/

I've found a workaround for now:

  • set testCoverageEnabled = false by default
  • when running unit tests (testDebugUnitTest), then set testCoverageEnabled = true

(I've done this with a property instead of manually changing the build.gradle each time, but omitted that here.)

UPDATE: It appears that the fabric plugin is an issue. Adding the following to the root build.gradle of a project which otherwise works with jacoco 0.8.0 makes it fail with the above jacoco exception:

 buildscript {

     repositories {
         google()
         jcenter()
+        maven { url 'https://maven.fabric.io/public' }
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:3.0.1'
+        classpath 'io.fabric.tools:gradle:1.+'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with ./gradlew clean assembleDebug using the root and app build.gradle configurations shown, then compare JaCoCo 0.8.0 behavior with and without the Fabric plugin. Use the reported ClassProbesAdapter stack trace as the starting point; done means the Android build completes with coverage enabled and the conflict is covered by a regression test or documented configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
build-system, mobile, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.