For an Android application project with dependency on a 3rd party library: App A → Lib B (AAR file), by doing ‘assembleDebug’ gradle command, byte code from the 3rd party library is instrumented by Jacoco when the plugin is applied and ‘testCoverageEnabled’ is set to true. The behavior can be verified by de-assembling the APK and inspecting byte code belonging the 3rd party library.
I suspect this is not actually coming from the built-in JaCoCo plugin, as it does not even support offline-instrumentation for Java code, let alone Android code.
I would suspect that the Android Gradle Plugin does this, or that you apply some other plugin that does this JaCoCo offline instrumentation.
I suspect this is not actually coming from the built-in JaCoCo plugin, as it does not even support offline-instrumentation for Java code, let alone Android code.
By just building the APK with ‘testCoverageEnabled’ set to true without running any test, and then looking at the byte code, I can see that 2 members are added to each class which matches the description below from Jacoco FAQ.
To collect execution data JaCoCo instruments the classes under test which adds two members to the classes: A private static field $jacocoData and a private static method $jacocoInit(). Both members are marked as synthetic. JaCoCo - FAQ
My questions are:
Isn’t that considered offline instrumentation? Or is there a different term for it?
Is there a way to exclude certain class/package from having the 2 class members added?
Isn’t that considered offline instrumentation? Or is there a different term for it?
Yes it is.
And that is exactly why I said your question has nothing to do with the built-in JaCoCo plugin which does not support offline instrumentation and does not have the testCoverageEnabled property you mentioned.
Is there a way to exclude certain class/package from having the 2 class members added?
Again, ask whoever does this offline instrumentation.
I would guess it probably is the Android Gradle Plugin which is a 3rd party plugin, but I’m not an Android developer, and I’m too lazy to google it for you right now.