Using JaCoCo plugin in Gradle for Android testing with Android Studio

4,235 views
Skip to first unread message

mmk...@gmail.com

unread,
Jul 24, 2014, 10:39:11 PM7/24/14
to jac...@googlegroups.com
Hi all,

I'm a beginner in JacoCo and encounter problem of jacoco.exec not created after running Android tests. Can you please help to point out what needs to be changed or done? Also, does it require using an argument for JaCoCo agent when executing test? Thank you very much!

I read the JaCoCo plug-in section in Gradle User Guide (http://www.gradle.org/docs/current/userguide/jacoco_plugin.html) and Android Studio page, as well as searching for answers in Google. One issue is that Gradle should not take both android and java plugins so I cannot use the test task from java plugin to specify JaCoCo destinationFile and classDumpFile values as stated in Gradle User Guide.

Dev. environment:
Gradle 2.0
JaCoCo 0.7.1.201405082137
JDK 1.7.0_65
Android compiled SDK version 20
Android build tools version 20.0.0
Android Studio 0.8.2
Android version on test device 4.2.2

logcat message from executing Android tests:
07-24 19:30:47.990 10149-10165/? W/System.err﹕ java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)

Below are the additions in the module's build.gradle file to support JaCoCo:
apply plugin: "jacoco"

android {
buildTypes {
debug {
testCoverageEnabled true
}
release {
testCoverageEnabled true
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
jacoco {
println "jacoco version"
version "0.7.1.201405082137"
}
}

jacoco {
toolVersion = "0.7.1.201405082137"
reportsDir = file("<absolute_path_to_project>/app/build/customJacocoReportDir")
}

def coverageSourceDirs = [
'<absolute_path_to_project>/app/src/main'
]

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
xml.destination = "<absolute_path_to_project>/app/build/reportXML"
html.enabled = true
html.destination = "<absolute_path_to_project>/app/build/reportHTML"
}
classDirectories = fileTree(
dir: '<absolute_path_to_project>/app/build/intermediates/coverage-instrumented-classes/debug',
)
sourceDirectories = files(coverageSourceDirs)
executionData = files("jacoco.exec")
}

Marc Hoffmann

unread,
Aug 4, 2014, 5:39:22 AM8/4/14
to jac...@googlegroups.com
Hi,

the JaCoCo runtime allows to configure the output location for the exec
file. You probably need to select a writable part of the file Android
system. See 'destfile' property:

http://www.eclemma.org/jacoco/trunk/doc/agent.html

As you are probably using offline instrumented classes for Android here
you find how to configure the JaCoCo runtime in this case:

http://www.eclemma.org/jacoco/trunk/doc/offline.html

Best regards,
-marc
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages