Fixed
Status Update
Comments
ta...@gmail.com <ta...@gmail.com> #2
can you share your android studio version
vi...@gmail.com <vi...@gmail.com> #3
Is this happening with Studio 3.0?
ss...@gmail.com <ss...@gmail.com> #4
Note: This worked for me on Windows 7 Pro 32-bit (with Android Studio 2.3.3). Seems like an issue with adt-branding module (which should contain the "/idea/AndroidStudioApplicationInfo.xml" resource).
ss...@gmail.com <ss...@gmail.com> #5
Hi, also happened on Mac Book Pro 15 retina mi-2015
MacOs Sierra 10.12.6
Android Studio 2.3.3
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
MacOs Sierra 10.12.6
Android Studio 2.3.3
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
vb...@gmail.com <vb...@gmail.com> #6
Thank you for this feedback. Your feedback helps make sure Android development tools are great! Given your issues has been resolved I am closing this issue.
xa...@android.com <xa...@android.com> #7
#3 It means that the library code is not instrumented, which means that you won't get code coverage for tests using the library code.
You can however put tests in the library and run these tests separately and that should be how you test your library anyway. The tests in the app should only test the app part.
I do realize that this is not always possible so we want to enable this anyway, but if you want to properly test your library code, test it in the library itself.
You can however put tests in the library and run these tests separately and that should be how you test your library anyway. The tests in the app should only test the app part.
I do realize that this is not always possible so we want to enable this anyway, but if you want to properly test your library code, test it in the library itself.
ss...@gmail.com <ss...@gmail.com> #8
@6: The question to me is, *why* is the library code not instrumented if the app code is. Is it because of issue 36949180 ? Also, what confuses me a bit is that there's no "instrumented" build type by default.
vb...@gmail.com <vb...@gmail.com> #9
[Comment deleted]
vb...@gmail.com <vb...@gmail.com> #10
#6: That's exactly how we test it. Each library project has it's own androidTest folder with test and is tested in separation but run with gradle wrapper of app project. When we run connectedCheck with coverage enabled, coverage for lib projects is 0.
xa...@android.com <xa...@android.com> #11
Right that's a different problem that I was just looking into.
We have code that prevents instrumenting the test code. However in case of a library, the test app == the library since the test app embeds the library inside itself. So instrumentation is disabled :\
I'll have to see if it's an easy fix.
We have code that prevents instrumenting the test code. However in case of a library, the test app == the library since the test app embeds the library inside itself. So instrumentation is disabled :\
I'll have to see if it's an easy fix.
ma...@gmail.com <ma...@gmail.com> #12
My project also depends on several library projects and has all tests in the application project. For this setup I could workaround the issue by doing the following:
1. Enable instrumentation for the debug build type in all library projects:
android {
buildTypes {
debug {
testCoverageEnabled true
}
}
}
2. Make sure the debug build type of the libraries gets published:
android {
publishNonDefault true
}
3. Make sure that the dependencies to the libraries point to the debug build type:
dependencies {
debugCompile project(path: 'library', configuration: 'debug')
}
4. The AARs of the libraries now all contain a jacocoagent.jar file. This leads to an 'already added' exception in the dex task of the app project, so make sure that they get deleted before dex is running, but after the AARs get exploded in your application project:
task deleteJacocoagentJar {
doLast {
getTransitiveProjectDependencies(this, 'debugCompile').each { project ->
delete "build/intermediates/exploded-aar/${rootProject.name}/${project.name }/unspecified/debug/libs/jacocoagent.jar"
}
}
}
def getTransitiveProjectDependencies(project, configuration) {
def projectDependencies = project.configurations."$configuration".getAllDependencies().withType(ProjectDependency)
def dependencyProjects = projectDependencies*.dependencyProject
dependencyProjects.each {
dependencyProjects += getTransitiveProjectDependencies(it, configuration)
}
return dependencyProjects.unique()
}
android {
applicationVariants.all { variant ->
variant.dex.dependsOn deleteJacocoagentJar
deleteJacocoagentJar.mustRunAfter variant.javaCompile
}
}
6. So far we can build an APK where also the classes from the library projects are instrumented, therefore thecoverage.ec file generated by 'connectedCheck' contains coverage information for those classes, too. Unfortunately the 'createDebugCoverageReport' task running after 'connectedCheck' still only uses the class and source files from the application project, and will therefore only contain coverage information for the application project. I have created my own task to create the Jacoco report, based on JacocoReportTask.groovy from the Android Gradle plugin. The JAR files from the classpath below were copied from the local Gradle cache to a folder 'jacoco' in the application project (just because I was too lazy to find out how to directly reference the files from the Gradle cache):
task createJacocoReport {
doLast {
File reportOutDir = file('build/outputs/reports/jacocoCoverage');
reportOutDir.deleteDir()
reportOutDir.mkdirs()
def buildDir = getBuildDir()
def projectDependencies = getTransitiveProjectDependencies(this, 'debugCompile')
getAnt().taskdef(name: 'reportWithJacoco',
classname: 'org.jacoco.ant.ReportTask',
classpath: 'jacoco/asm-debug-all-5.0.1.jar:jacoco/org.jacoco.agent-0.7.1.201405082137.jar:jacoco/org.jacoco.ant-0.7.1.201405082137.jar:jacoco/org.jacoco.core-0.7.1.201405082137.jar:jacoco/org.jacoco.report-0.7.1.201405082137.jar')
getAnt().reportWithJacoco {
executiondata {
fileset(file: "${buildDir}/outputs/code-coverage/connected/coverage.ec ")
}
structure(name: 'coverage-test') {
sourcefiles {
fileset(dir: file('src'))
fileset(dir: file("${buildDir}/generated/source/aidl/debug"))
fileset(dir: file("${buildDir}/generated/source/rs/debug"))
projectDependencies.each { Project project ->
fileset(dir: project.file('src'))
fileset(dir: file("${project.getBuildDir()}/generated/source/aidl/debug"))
fileset(dir: file("${project.getBuildDir()}/generated/source/rs/debug"))
}
}
classfiles {
fileset(dir: file("${buildDir}/intermediates/classes/debug"),
excludes: "**/R.class,**/R*.class,**/Manifest.class,**/Manifest*.class,**/BuildConfig.class")
projectDependencies.each { Project project ->
fileset(dir: file("${project.getBuildDir()}/intermediates/classes/debug"),
excludes: "**/R.class,**/R*.class,**/Manifest.class,**/Manifest*.class,**/BuildConfig.class")
}
}
}
html(destdir: reportOutDir)
xml(destfile: new File(reportOutDir, "report.xml"))
}
}
}
1. Enable instrumentation for the debug build type in all library projects:
android {
buildTypes {
debug {
testCoverageEnabled true
}
}
}
2. Make sure the debug build type of the libraries gets published:
android {
publishNonDefault true
}
3. Make sure that the dependencies to the libraries point to the debug build type:
dependencies {
debugCompile project(path: 'library', configuration: 'debug')
}
4. The AARs of the libraries now all contain a jacocoagent.jar file. This leads to an 'already added' exception in the dex task of the app project, so make sure that they get deleted before dex is running, but after the AARs get exploded in your application project:
task deleteJacocoagentJar {
doLast {
getTransitiveProjectDependencies(this, 'debugCompile').each { project ->
delete "build/intermediates/exploded-aar/${rootProject.name}/${
}
}
}
def getTransitiveProjectDependencies(project, configuration) {
def projectDependencies = project.configurations."$configuration".getAllDependencies().withType(ProjectDependency)
def dependencyProjects = projectDependencies*.dependencyProject
dependencyProjects.each {
dependencyProjects += getTransitiveProjectDependencies(it, configuration)
}
return dependencyProjects.unique()
}
android {
applicationVariants.all { variant ->
variant.dex.dependsOn deleteJacocoagentJar
deleteJacocoagentJar.mustRunAfter variant.javaCompile
}
}
6. So far we can build an APK where also the classes from the library projects are instrumented, therefore the
task createJacocoReport {
doLast {
File reportOutDir = file('build/outputs/reports/jacocoCoverage');
reportOutDir.deleteDir()
reportOutDir.mkdirs()
def buildDir = getBuildDir()
def projectDependencies = getTransitiveProjectDependencies(this, 'debugCompile')
getAnt().taskdef(name: 'reportWithJacoco',
classname: 'org.jacoco.ant.ReportTask',
classpath: 'jacoco/asm-debug-all-5.0.1.jar:jacoco/org.jacoco.agent-0.7.1.201405082137.jar:jacoco/org.jacoco.ant-0.7.1.201405082137.jar:jacoco/org.jacoco.core-0.7.1.201405082137.jar:jacoco/org.jacoco.report-0.7.1.201405082137.jar')
getAnt().reportWithJacoco {
executiondata {
fileset(file: "${buildDir}/outputs/code-coverage/connected/
}
structure(name: 'coverage-test') {
sourcefiles {
fileset(dir: file('src'))
fileset(dir: file("${buildDir}/generated/source/aidl/debug"))
fileset(dir: file("${buildDir}/generated/source/rs/debug"))
projectDependencies.each { Project project ->
fileset(dir: project.file('src'))
fileset(dir: file("${project.getBuildDir()}/generated/source/aidl/debug"))
fileset(dir: file("${project.getBuildDir()}/generated/source/rs/debug"))
}
}
classfiles {
fileset(dir: file("${buildDir}/intermediates/classes/debug"),
excludes: "**/R.class,**/R*.class,**/Manifest.class,**/Manifest*.class,**/BuildConfig.class")
projectDependencies.each { Project project ->
fileset(dir: file("${project.getBuildDir()}/intermediates/classes/debug"),
excludes: "**/R.class,**/R*.class,**/Manifest.class,**/Manifest*.class,**/BuildConfig.class")
}
}
}
html(destdir: reportOutDir)
xml(destfile: new File(reportOutDir, "report.xml"))
}
}
}
ma...@gmail.com <ma...@gmail.com> #13
Martin - is your technique still working? I end up with: taskdef class org.jacoco.ant.ReportTask cannot be found when running the create report task.
ma...@gmail.com <ma...@gmail.com> #14
I haven't tried recently but it should still be working. It sounds like the Jacoco JAR files are missing, did you check that they are in the correct folder?
je...@google.com <je...@google.com>
be...@google.com <be...@google.com>
lm...@gmail.com <lm...@gmail.com> #15
The technique above doesnot work for me.
First, i had to fix the deletion of the jar because the location has changed :
task deleteJacocoagentJar {
doLast {
getTransitiveProjectDependencies(this, 'debugCompile').each { project ->
delete "build/intermediates/exploded-aar/${rootProject.name}/${project.name }/unspecified/debug/jars/libs/jacocoagent.jar"
}
}
}
The apk build is ok but at runtime, it can't find the jacoco classes.
Suppressed: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_773e439.Offline
5528 AndroidRuntime E at java.lang.Class.classForName(Native Method)
5528 AndroidRuntime E at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
5528 AndroidRuntime E at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
5528 AndroidRuntime E at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
First, i had to fix the deletion of the jar because the location has changed :
task deleteJacocoagentJar {
doLast {
getTransitiveProjectDependencies(this, 'debugCompile').each { project ->
delete "build/intermediates/exploded-aar/${rootProject.name}/${
}
}
}
The apk build is ok but at runtime, it can't find the jacoco classes.
Suppressed: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_773e439.Offline
5528 AndroidRuntime E at java.lang.Class.classForName(Native Method)
5528 AndroidRuntime E at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
5528 AndroidRuntime E at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
5528 AndroidRuntime E at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
kw...@gmail.com <kw...@gmail.com> #17
Has anyone found a solution for this?
sr...@gmail.com <sr...@gmail.com> #18
Is this issue still open? I need the solution badly
cl...@gmail.com <cl...@gmail.com> #19
Thanks Martin~! Your solution helped me a lot~!
cl...@gmail.com <cl...@gmail.com> #20
please fix this issue ASAP~!
be...@google.com <be...@google.com>
ch...@gmail.com <ch...@gmail.com> #21
If you have an Android application with Java and Android modules, the way to include both the Java and Android Modules to your code coverage is follow this
use this guy's project for your general configuration
https://github.com/serj-lotutovici/jacoco-example/blob/master/build.gradle
and add the following lines to your Java modules
apply plugin: 'jacoco'
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
dependencies {
......
......
}
test {
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/testDebug.exec")
}
}
use this guy's project for your general configuration
and add the following lines to your Java modules
apply plugin: 'jacoco'
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
dependencies {
......
......
}
test {
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/testDebug.exec")
}
}
[Deleted User] <[Deleted User]> #22
Any update?
ih...@gmail.com <ih...@gmail.com> #23
I'm facing the same problem. Have anybody figured it out?
ad...@google.com <ad...@google.com>
hu...@google.com <hu...@google.com> #24
There were regressions multiple times due to various reasons such as the scoped storage, internal refactoring in AGP and support for the Android test orchestrator. It has been fixed in the latest version (7.1.0-alpha05) and we have added integration tests to prevent us from the future regressions. Let us know if the coverage still does not work with the latest version. I'm going to mark this bug as fixed now and will reopen if the issue still exists.
Description