I'm using JaCoCo plugin for code coverage in my Android project. When I open sonar it shows me that following line isn't covered.
I'm using SonarQube Version 4.5.1 and JaCoCo Gradle plugin 0.7.1.201405082137.
Is this a bug in JaCoCo plugin? How can I fix it?
Edit: reported to Gradle forum.
Very strange, but if I change code style, then everything is fine.
I'll report this to Gradle community.
Related
I have this exception after upgrade to the Android Gradle 3.0.1 version.
I use Jacoco in my multimodule android project.
java.nio.channels.OverlappingFileLockException
at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:1063)
at java.nio.channels.FileChannel.lock(FileChannel.java:1053)
at org.jacoco.agent.rt.internal_290345e.output.FileOutput.openFile(FileOutput.java:69)
at org.jacoco.agent.rt.internal_290345e.output.FileOutput.writeExecutionData(FileOutput.java:53)
at org.jacoco.agent.rt.internal_290345e.Agent.shutdown(Agent.java:137)
at org.jacoco.agent.rt.internal_290345e.Agent$1.run(Agent.java:54)
Any ideas on how to fix this error?
I faced the same issue during Jacoco report generation. my issue was solved by adding the following entries on the build.Gradle file
jacoco {
toolVersion = "0.8.8"
}
According to this Github issue (not yet fixed), you should add this to your tests :
#PowerMockIgnore("org.jacoco.agent.rt.*")
I've got a problem when I launch a build on Jenkins. I would like to have the coverage report of my instrumented tests in Jenkins but it fails due to an incompatible version of Jacoco.
In my Android project, I've added the line apply plugin: 'jacoco' in the app/build.gradle file.
My Android project use the gradle plugin 3.0.1 version.
In Jenkins, I set up my application like this:
In Jenkins, I've installed the JaCoCo plugin 3.0.1 version.
When I run a build in Jenkins with this configuration, it goes well but I don't get the coverage report of the instrumented tests.
So, I change the settings like this:
When I run a build, in the Console output, I get the following message:
ERROR: Step ‘Record JaCoCo coverage report’ aborted due to exception:
org.jacoco.core.data.IncompatibleExecDataVersionException: Cannot read execution data version 0x1006. This version of JaCoCo uses execution data version 0x1007.
On the Jenkins wiki, I read that there is a compatibility problem between different versions of Jenkins and JaCoCo: https://wiki.jenkins.io/display/JENKINS/JaCoCo+Plugin.
So, I tried to use a 7.5+ version in my Android project by adding this line in the build.gradle file:
jacoco {
toolVersion '0.7.5+'
}
But it still fails... :-(
I don't understand why it works with the *.exec files only but not when I add the *.ec files.
Someone see what I missed?
After I update Android studio to 3.0 and migrated my project by following this instruction
I got the error like this:
* What went wrong:
Execution failed for task
':app:transformClassesWithFirebasePerformancePluginForDevDebug'.
> SHA-256 digest error for org/jacoco/agent/rt/RT.class
I tracked and found that the root cause came from this code in build.gradle file.
debug {
...
// Run code coverage reports by default on debug builds.
testCoverageEnabled = true
}
Because when I commented this line of code the project built fine. I haven't got this problem when I used Android Studio 2.3.
I had searched some related topics and found that somebody said disable instant run will solve but unfortunately in not work for my case.
Dose anyone has any suggestion to solve this issue?
Thanks
UPDATE 2:
Firebase Support still says the fix is not rolled out, but I tried it out today with the latest versions of firebase-perf and jacoco and it works.
UPDATE 1:
firebase-perf doesn't work with jacoco when Java 1.8 support is enabled. Firebase support team was able to replicate this and is investigating.
Original post:
This looks to be triggered when firebase-perf plugin is enabled. I filed a bug with Firebase team and will update if I get an answer.
As a temporary workaround, just commenting out apply plugin ... firebase-perf should help. It will disable Automatic Traces but #AddTrace and newTrace should still work.
In my case testCoverageEnabled is set conditionally based on a project property and I didn't need firebase-perf plugin for when evaluating the coverage, so I just disabled the plugin:
if (!project.hasProperty('coverageRun')) {
apply plugin: 'com.google.firebase.firebase-perf'
}
// < ... >
if (project.hasProperty('coverageRun')) {
testCoverageEnabled true
}
I am trying to get code coverage working for a new empty Android project using Gradle in Android Studio.
I managed to get Sonar working but I can't seem to figure it out for the code coverage. (never done anything like it before)
I have looked at JaCoCo but it is not compatible with Android. The same goes for Cobertura. And it seems Emma doesn't work with Gradle yet.
I am using Gradle 1.11, Android Studio 0.5.1 and Sonar Runner 2.3
JaCoCo is now supported in Android Studio when using build tools version 0.10.0
New Build System
Release Notes:
0.10.0
....
Test code coverage support with Jacoco
Enable in the tested Build Type with testCoverageEnabled = true
HTML and XML Report generated in build/reports/coverage
Configure version of Jacoco with
android {
jacoco {
version = '0.6.2.201302030002'
}
}
Known issue: This is not compatible with using Dagger.
.....
Please refer to this answer. https://stackoverflow.com/a/25029501/973483
You should be able to use jacoco and enable code coverage on android project as long as you are using Java version 1.5. It should work with mockito, dagger and espresso.
If you, however, switch to Java 1.6 or above, you will have issues enabling code coverage
Is there a way to to have a gradle build that will generate code coverage from robolectric test that can be sent to sonar?
As far as I can tell: At this time, No.
In order to have code coverage you need Emma support and that's not yet fixed in the android gradle build plugin. It's supposed to come in version 0.8.+ but it was also "supposed" to come in version 0.6+ so don't hold your breath.
Roadmap: http://tools.android.com/tech-docs/new-build-system/roadmap
Related Emma Issue: https://code.google.com/p/android/issues/detail?id=60964