Status Update
Comments
my...@gmail.com <my...@gmail.com> #2
can you share your android studio version
ja...@google.com <ja...@google.com> #3
Is this happening with Studio 3.0?
st...@google.com <st...@google.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).
cm...@google.com <cm...@google.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)
my...@gmail.com <my...@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.
be...@google.com <be...@google.com> #7
I imagine the problem is about both the jacoco and android plugins using Jacoco classes (potentially in different class loaders?). For instrumented tests (running on device), we handle all Jacoco logic ourselves (no need for the jacoco plugin), we have not extended this to handle unit tests as well :(
Still - can you be more specific about exact repro steps? I tried applying your jacoco.gradle file on a simple project and everything worked fine when I run ./gradlew clean :app:createDebugUnitTestCoverageReport (see attached project). I'm also surprised to see DexPathList in the error message - are you using Robolectric by any chance?
PS. You can find the version used by the plugin for example here:http://search.maven.org/#artifactdetails%7Ccom.android.tools.build%7Cgradle-core%7C2.1.3%7Cjar
Still - can you be more specific about exact repro steps? I tried applying your jacoco.gradle file on a simple project and everything worked fine when I run ./gradlew clean :app:createDebugUnitTestCoverageReport (see attached project). I'm also surprised to see DexPathList in the error message - are you using Robolectric by any chance?
PS. You can find the version used by the plugin for example here:
be...@google.com <be...@google.com> #8
Forgot the attachment.
my...@gmail.com <my...@gmail.com> #9
Thanks, I think I've narrowed down the problem to an incompatibility with the google-services plugin.
After adding this classpath dependency to your sample project (top of app gradle script) I was able to reproduce the problem:
buildscript {
dependencies {
classpath 'com.google.gms:google-services:2.1.2'
}
}
Upgrading that version to 3.0.0 resolved the crash.
This requires me to upgrade to Play Services 9.0.0, which isn't going to be reasonable for a while.
Hope this helps you find the root cause and hopefully an update in the android gradle plugin will fix it.
After adding this classpath dependency to your sample project (top of app gradle script) I was able to reproduce the problem:
buildscript {
dependencies {
classpath 'com.google.gms:google-services:2.1.2'
}
}
Upgrading that version to 3.0.0 resolved the crash.
This requires me to upgrade to Play Services 9.0.0, which isn't going to be reasonable for a while.
Hope this helps you find the root cause and hopefully an update in the android gradle plugin will fix it.
my...@gmail.com <my...@gmail.com> #10
Any update on this?
I can reliably reproduce it using the above dependency. This issue is preventing me from upgrading gradle or the Android gradle plugin.
Thanks.
I can reliably reproduce it using the above dependency. This issue is preventing me from upgrading gradle or the Android gradle plugin.
Thanks.
be...@google.com <be...@google.com> #11
Can you please provide exact repro steps that work reliably for you?
I tried adding the buildscript snippet to app/build.gradle in jacoco.zip in #8 (with misssing "repositories { jcenter() }" block) and it worked fine.
Then I added "apply plugin: 'com.google.gms.google-services'" to the end of app/build.gradle and added a simple google-services.json file, but it still works fine.
I'm testing by running ./gradlew clean connectedCheck
I tried adding the buildscript snippet to app/build.gradle in jacoco.zip in #8 (with misssing "repositories { jcenter() }" block) and it worked fine.
Then I added "apply plugin: 'com.google.gms.google-services'" to the end of app/build.gradle and added a simple google-services.json file, but it still works fine.
I'm testing by running ./gradlew clean connectedCheck
my...@gmail.com <my...@gmail.com> #12
I should have been clearer - I was reproducing the issue by deploying and launching the app. I've added a test so the problem is now reproduced using ./gradlew clean connectedCheck
Applying the google-services plugin isn't even required (adding it doesn't fix it either).
This project should reproduce the problem:https://github.com/myanimal/android-issue-220640
Applying the google-services plugin isn't even required (adding it doesn't fix it either).
This project should reproduce the problem:
be...@google.com <be...@google.com> #13
OK, so the problem is that google-services 2.1.2 has a dependency on an old version of the android plugin (the 2.1.2 version). On top of that, you're hitting a strange corner case of gradle dependency management, where buildScript dependencies in /build.gradle and /app/build.gradle are not resolved against each other.
So there are two workarounds:
1. Move the "classpath 'com.google.gms:google-services:2.1.2'" line to top-level build.gradle, next to the android plugin.
2. Alternatively, you can keep it in app/build.gradle like this:
classpath('com.google.gms:google-services:2.1.2') {
exclude group: 'org.jacoco'
}
But I recommend you do the former.
As discussed- over to you Chris, let's see if we can make something clever on our end to handle this.
So there are two workarounds:
1. Move the "classpath 'com.google.gms:google-services:2.1.2'" line to top-level build.gradle, next to the android plugin.
2. Alternatively, you can keep it in app/build.gradle like this:
classpath('com.google.gms:google-services:2.1.2') {
exclude group: 'org.jacoco'
}
But I recommend you do the former.
As discussed- over to you Chris, let's see if we can make something clever on our end to handle this.
ja...@gmail.com <ja...@gmail.com> #14
OK So i had a similar problem to this. And here are my findings to the same.
I created a sample project and started adding all my dependencies 1 by 1. In case of a smaller project with say 5-10 dependencies this is doable. It might not work with projects having more dependencies.
Then i added below in my build.gradle. This is basically the gradle plugin for using Spoon to test your application on multiple devices simultaneously.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.1.0'
}
}
Note: I tried the latest as well 1.2.2 with the client 1.6.4 same result.
And i was able to replicate the same crash when launching the application.
I disabled it and life was back to normal :)
I am planning to create a sample project running Android Build Tools Gradle 2.1.3 and Gradle 2.14.1 using spoon gradle
Link:https://github.com/stanfy/spoon-gradle-plugin
Will update the issue in this thread once i have created this.
I guess this is a bug with Spoon-gradle-plugin instead of build tools.
BR,
Jayshil
I created a sample project and started adding all my dependencies 1 by 1. In case of a smaller project with say 5-10 dependencies this is doable. It might not work with projects having more dependencies.
Then i added below in my build.gradle. This is basically the gradle plugin for using Spoon to test your application on multiple devices simultaneously.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.1.0'
}
}
Note: I tried the latest as well 1.2.2 with the client 1.6.4 same result.
And i was able to replicate the same crash when launching the application.
I disabled it and life was back to normal :)
I am planning to create a sample project running Android Build Tools Gradle 2.1.3 and Gradle 2.14.1 using spoon gradle
Link:
Will update the issue in this thread once i have created this.
I guess this is a bug with Spoon-gradle-plugin instead of build tools.
BR,
Jayshil
my...@gmail.com <my...@gmail.com> #15
[Comment deleted]
my...@gmail.com <my...@gmail.com> #16
Thanks for the suggested workarounds. Both of them work on the sample project, but neither of them work on my main project.
I haven't been able to figure out what difference is causing the issue yet, but this is still preventing me from upgrading to gradle 2.14.1 (security fix).
I will continue to try to reproduce the crash on the sample project.
I haven't been able to figure out what difference is causing the issue yet, but this is still preventing me from upgrading to gradle 2.14.1 (security fix).
I will continue to try to reproduce the crash on the sample project.
an...@gmail.com <an...@gmail.com> #17
2.2/2.14.1 + jacoco 0.7.x + robolectric 3.1.1 gives me hard time too.
Basically i tried different combinations of the plugin/gradle/jacoco/robolectric versions but always get mixture of the exceptions below:
IllegalStateException: Class ... is already instrumented
NoClassDefFoundError: org/jacoco/agent/rt/internal_773e439/Offline
Is there any workaround?
Basically i tried different combinations of the plugin/gradle/jacoco/robolectric versions but always get mixture of the exceptions below:
IllegalStateException: Class ... is already instrumented
NoClassDefFoundError: org/jacoco/agent/rt/internal_773e439/Offline
Is there any workaround?
to...@gmail.com <to...@gmail.com> #18
I've got an ugly workaround that allows me to use Android build gradle 2.2 and gradle 2.14.1 with Jacoco 0.7.7.201606060606 (to fix the code coverage report when running unit tests with Robolectric).
It seems Android gradle 2.2 is hardwired to use Jacoco 0.7.5.201505241946. Forcing it to use a new version by using resolutionStrategy doesn't work. So I extracted 'jacocoagent.jar' from .gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.agent/0.7.5.201505241946/2f0308aaf7b3f2e133d410de8af49739cb0964aa/org.jacoco.agent-0.7.5.201505241946.jar to the jacoco folder in my root project.
In app build.gradle, add
afterEvaluate {
if (tasks.findByPath('unzipJacocoAgent') != null) {
unzipJacocoAgent.onlyIf { false }
transformClassesWithJacocoForDevDebug.dependsOn copyJacocoAgent
}
}
task copyJacocoAgent(type: Copy) {
from "${rootProject.projectDir}/jacoco"
into "${project.buildDir}/intermediates/jacoco"
}
Change ` transformClassesWithJacocoForDevDebug` to match your product flavour and add more if necessary.
It seems Android gradle 2.2 is hardwired to use Jacoco 0.7.5.201505241946. Forcing it to use a new version by using resolutionStrategy doesn't work. So I extracted 'jacocoagent.jar' from .gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.agent/0.7.5.201505241946/2f0308aaf7b3f2e133d410de8af49739cb0964aa/org.jacoco.agent-0.7.5.201505241946.jar to the jacoco folder in my root project.
In app build.gradle, add
afterEvaluate {
if (tasks.findByPath('unzipJacocoAgent') != null) {
unzipJacocoAgent.onlyIf { false }
transformClassesWithJacocoForDevDebug.dependsOn copyJacocoAgent
}
}
task copyJacocoAgent(type: Copy) {
from "${rootProject.projectDir}/jacoco"
into "${project.buildDir}/intermediates/jacoco"
}
Change ` transformClassesWithJacocoForDevDebug` to match your product flavour and add more if necessary.
an...@gmail.com <an...@gmail.com> #19
well I manage to override jacoco version by
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.jacoco:org.jacoco.core:$jacocoVersion")
classpath("org.jacoco:org.jacoco.report:$jacocoVersion")
classpath("org.jacoco:org.jacoco.agent:$jacocoVersion")
classpath("org.jacoco:org.jacoco.ant:$jacocoVersion")
classpath (androidGradleClasspath)
}
}
so I got rid of NoClassDefFoundError: org/jacoco/agent/rt/internal_773e439/Offline
However I still have many IllegalStateException: Class ... is already instrumented
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.jacoco:org.jacoco.core:$jacocoVersion")
classpath("org.jacoco:org.jacoco.report:$jacocoVersion")
classpath("org.jacoco:org.jacoco.agent:$jacocoVersion")
classpath("org.jacoco:org.jacoco.ant:$jacocoVersion")
classpath (androidGradleClasspath)
}
}
so I got rid of NoClassDefFoundError: org/jacoco/agent/rt/internal_773e439/Offline
However I still have many IllegalStateException: Class ... is already instrumented
to...@gmail.com <to...@gmail.com> #20
Thanks! When I looked at the dependencies report, I could see everything use the Jacoco version I specified but I should have thought that Android build also uses Jacoco as part of the build process. I've now removed my ugly workaround and added what you suggested, and everything (app launch and unit testing with Robolectric and code coverage report) still works fine.
My root project's build script now contains:-
buildscript {
. . .
dependencies {
. . .
classpath("org.jacoco:org.jacoco.agent:$versions.jacoco")
classpath("org.jacoco:org.jacoco.ant:$versions.jacoco")
classpath("org.jacoco:org.jacoco.core:$versions.jacoco")
classpath("org.jacoco:org.jacoco.report:$versions.jacoco")
classpath "com.android.tools.build:gradle:$versions.android_build"
}
}
allprojects {
. . .
configurations {
all {
resolutionStrategy {
force "org.jacoco:org.jacoco.agent:$versions.jacoco"
force "org.jacoco:org.jacoco.ant:$versions.jacoco"
force "org.jacoco:org.jacoco.core:$versions.jacoco"
force "org.jacoco:org.jacoco.report:$versions.jacoco"
}
}
}
}
My root project's build script now contains:-
buildscript {
. . .
dependencies {
. . .
classpath("org.jacoco:org.jacoco.agent:$versions.jacoco")
classpath("org.jacoco:org.jacoco.ant:$versions.jacoco")
classpath("org.jacoco:org.jacoco.core:$versions.jacoco")
classpath("org.jacoco:org.jacoco.report:$versions.jacoco")
classpath "com.android.tools.build:gradle:$versions.android_build"
}
}
allprojects {
. . .
configurations {
all {
resolutionStrategy {
force "org.jacoco:org.jacoco.agent:$versions.jacoco"
force "org.jacoco:org.jacoco.ant:$versions.jacoco"
force "org.jacoco:org.jacoco.core:$versions.jacoco"
force "org.jacoco:org.jacoco.report:$versions.jacoco"
}
}
}
}
an...@gmail.com <an...@gmail.com> #21
Finally I found a way to get rid of "IllegalStateException: Class ... is already instrumented".
Internally the android gradle plugin runs an offline jacoco instrumentation for all dependencies of the module, but not over the module itself. So when it runs the module tests with the jacocoagent then the classpath has mixture of instrumented and not instrumented classes so the jacocoagent complains and throws "Class ... is already instrumented"
Since I have quite a number of modules and some tests are not pure unit tests (rather integration tests) I had to set "jacoco.includes" explicitly to avoid the annoying exceptions.
something like below
android {
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
includes = [
getClassesFrom("${project.buildDir}/intermediates/classes/release/"),
getClassesFrom("${project.buildDir}/intermediates/classes/test/release/"),
].flatten()
}
}
}
buildTypes {
release {
testCoverageEnabled = getBooleanProperty('testCoverageEnabled', false);
}
}
}
where getClassesFrom(dir) returns ['com.some.package.ClassName',...]
Internally the android gradle plugin runs an offline jacoco instrumentation for all dependencies of the module, but not over the module itself. So when it runs the module tests with the jacocoagent then the classpath has mixture of instrumented and not instrumented classes so the jacocoagent complains and throws "Class ... is already instrumented"
Since I have quite a number of modules and some tests are not pure unit tests (rather integration tests) I had to set "jacoco.includes" explicitly to avoid the annoying exceptions.
something like below
android {
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
includes = [
getClassesFrom("${project.buildDir}/intermediates/classes/release/"),
getClassesFrom("${project.buildDir}/intermediates/classes/test/release/"),
].flatten()
}
}
}
buildTypes {
release {
testCoverageEnabled = getBooleanProperty('testCoverageEnabled', false);
}
}
}
where getClassesFrom(dir) returns ['com.some.package.ClassName',...]
vi...@gmail.com <vi...@gmail.com> #22
[Comment deleted]
ol...@gmail.com <ol...@gmail.com> #23
I have the same issue in my project with multiple modules.
My project default configuration:
- gradle: 2.14.1
- gradle: plugin 2.1.3
- jacoco: default version
Also, I have tried to combine:
- gradle 2.14, 2.14.1, 3.0, 3.1
- gradle plugin 2.1.2, 2.1.3, 2.2.0
- jacoco 0.7.5.201505241946, 0.7.6.201602180812, 0.7.7.201606060606
Every time the same result - app crashes on launch:
"NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_b0d6a23/Offline";
"ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_b0d6a23.Offline" on path: DexPathList...";
ect.
The workarounds that mentioned above did not help me to fix the issue.
Does somebody know when this issue will be fixed?
My project default configuration:
- gradle: 2.14.1
- gradle: plugin 2.1.3
- jacoco: default version
Also, I have tried to combine:
- gradle 2.14, 2.14.1, 3.0, 3.1
- gradle plugin 2.1.2, 2.1.3, 2.2.0
- jacoco 0.7.5.201505241946, 0.7.6.201602180812, 0.7.7.201606060606
Every time the same result - app crashes on launch:
"NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_b0d6a23/Offline";
"ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_b0d6a23.Offline" on path: DexPathList...";
ect.
The workarounds that mentioned above did not help me to fix the issue.
Does somebody know when this issue will be fixed?
ch...@google.com <ch...@google.com> #24
Removing the release exemption as we start to resolve bugs in Android Studio 2.3.
mo...@gmail.com <mo...@gmail.com> #25
Has this been fixed yet! We still face this issue running Android Studio 2.3, gradle: 3.3, gradle plugin 2.3.0 and jacoco with 0.7.9
cm...@google.com <cm...@google.com>
an...@gmail.com <an...@gmail.com> #26
Any updates on this issue ?
It 's is still reproducible in gradle 2.2.3 and jacoco 0.7.6.20160218081.
It 's is still reproducible in gradle 2.2.3 and jacoco 0.7.6.20160218081.
dc...@gmail.com <dc...@gmail.com> #27
Hi!
Still facing a similar issue... Using:
* Android Studio 3.0 canary 9
* Android Gradle plugin 3.0.0-alpha9
* Gradle 4.1-rc1
* Jacoco version: 0.7.5.201505241946
The exception thrown while starting a "gradle assembleDebug" apk is:
* java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_773e439.Offline"
Any updates on this issue?
Still facing a similar issue... Using:
* Android Studio 3.0 canary 9
* Android Gradle plugin 3.0.0-alpha9
* Gradle 4.1-rc1
* Jacoco version: 0.7.5.201505241946
The exception thrown while starting a "gradle assembleDebug" apk is:
* java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_773e439.Offline"
Any updates on this issue?
ga...@google.com <ga...@google.com> #28
We are now using resolution strategy to force Jacoco agent runtime jar to have the same version as Jacoco core we use for offline instrumentation, so you should not be seeing ClassNotFoundException any more. In case you see it again, please submit a new bug report.
Jacoco 0.7.4.201502262128 is default version for plugin 3.0.0-beta1, as we cannot upgrade it due to bug in dx,https://issuetracker.google.com/37116789 . You can still use newer versions by adding it to buildscript classpath as in #19, but you might hit this issue.
If you are using Gradle's built-in Jacoco plugin, you need to use the same version as Android plugin. Here are Gradle's docs how to set version -https://docs.gradle.org/current/userguide/jacoco_plugin.html . We would like to add support for test coverage for unit tests (tracked in https://issuetracker.google.com/64744476 ), so you should not need Jacoco plugin after that.
Fix should be in 3.0.0-beta4, ag/Ieb5740b134dffb477042796a55f68f9344430164.
Jacoco 0.7.4.201502262128 is default version for plugin 3.0.0-beta1, as we cannot upgrade it due to bug in dx,
If you are using Gradle's built-in Jacoco plugin, you need to use the same version as Android plugin. Here are Gradle's docs how to set version -
Fix should be in 3.0.0-beta4, ag/Ieb5740b134dffb477042796a55f68f9344430164.
er...@gmail.com <er...@gmail.com> #29
What is the easiest way for us to find the jacoco version of the android plugin?
ga...@google.com <ga...@google.com> #30
Execute `./gradlew buildEnvironment` on project using the Android plugin to get all of your buildscript dependencies. One of the listed transitive dependencies will be Jacoco, and there you can see the version.
er...@gmail.com <er...@gmail.com> #31
Thanks that is definitely a handy gradle task.
I noticed gradle wasn't able to find beta-4. I am assuming it is still in development? Is there somewhere we can keep an eye out for it's release?
I noticed gradle wasn't able to find beta-4. I am assuming it is still in development? Is there somewhere we can keep an eye out for it's release?
ry...@gmail.com <ry...@gmail.com> #32
I ran into this problem today. We are applying the jacoco plugin to a gradle plugin we wrote. That plugin is then applied to our libraries. My tests were running fine, both instrumentation and unit tests and my test coverage was good. Then I try to launch the app and its crashing with this exception. I set the version of jacoco plugin to 0.7.9 and added this guy to our build.gradle in our library: // compile 'org.jacoco:org.jacoco.agent:0.7.9:runtime'
That fixed the crasher. But it created a separate issue where duplicate jacoco files were ending up only in the android test apk. Why only the android test apk? I have no idea, I am curious how that apk is built differently from my debug apk. I went ahead and updated to classpath 'com.android.tools.build:gradle:3.0.0-beta2' and removed the jacoco.agent dependency and that fixed the issue for me.
That fixed the crasher. But it created a separate issue where duplicate jacoco files were ending up only in the android test apk. Why only the android test apk? I have no idea, I am curious how that apk is built differently from my debug apk. I went ahead and updated to classpath 'com.android.tools.build:gradle:3.0.0-beta2' and removed the jacoco.agent dependency and that fixed the issue for me.
th...@gmail.com <th...@gmail.com> #33
Same here. My gradle plugin version is 2.3.3, and don't wanna update to 3.0.0-beta2.
I've tried all different combinations mentioned above, what I can tell is, below workaround works for me.
1. Add jacoco classpath to the top-level build.gradle:
buildscript {
...
dependencies {
...
classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
classpath "org.jacoco:org.jacoco.ant:$jacoco_version"
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
classpath "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
2. Force to use the same jacoco version in application's build.gradle:
configurations.all {
resolutionStrategy {
...
force "org.jacoco:org.jacoco.agent:$jacoco_version"
force "org.jacoco:org.jacoco.ant:$jacoco_version"
force "org.jacoco:org.jacoco.core:$jacoco_version"
force "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
I've tried all different combinations mentioned above, what I can tell is, below workaround works for me.
1. Add jacoco classpath to the top-level build.gradle:
buildscript {
...
dependencies {
...
classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
classpath "org.jacoco:org.jacoco.ant:$jacoco_version"
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
classpath "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
2. Force to use the same jacoco version in application's build.gradle:
configurations.all {
resolutionStrategy {
...
force "org.jacoco:org.jacoco.agent:$jacoco_version"
force "org.jacoco:org.jacoco.ant:$jacoco_version"
force "org.jacoco:org.jacoco.core:$jacoco_version"
force "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
ry...@gmail.com <ry...@gmail.com> #34
what version of jacoco you using? ^
th...@gmail.com <th...@gmail.com> #35
0.7.9
an...@gmail.com <an...@gmail.com> #36
In Android Plugin 3.1.0-alpha07 it seems that Jacoco dependency was changed to 0.7.9
With the version of Plugin and Gradle 4.5 (don't think it matters) I don't have the issue anymore on my project.
So Looking forward for Android Studio and Gradle Plugin 3.1 release! (there's 3.1.0-beta2 at the moment)
With the version of Plugin and Gradle 4.5 (don't think it matters) I don't have the issue anymore on my project.
So Looking forward for Android Studio and Gradle Plugin 3.1 release! (there's 3.1.0-beta2 at the moment)
da...@gmail.com <da...@gmail.com> #37
Just as a commment, if google wants quality apps should focus on this kind of things, so people could know and measure their own quality better...
da...@gmail.com <da...@gmail.com> #38
And they are doing it! Just noticed that it's fixed. Thanks
[Deleted User] <[Deleted User]> #39
I'm having this issue while trying to upgrade to Gradle 7.0.2 and $jacoco_version=0.8.7 but no luck:
1. Add jacoco classpath to the top-level build.gradle:
buildscript {
...
dependencies {
...
classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
classpath "org.jacoco:org.jacoco.ant:$jacoco_version"
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
classpath "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
2. Force to use the same jacoco version in application's build.gradle:
configurations.all {
resolutionStrategy {
...
force "org.jacoco:org.jacoco.agent:$jacoco_version"
force "org.jacoco:org.jacoco.ant:$jacoco_version"
force "org.jacoco:org.jacoco.core:$jacoco_version"
force "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
any help pls :/
1. Add jacoco classpath to the top-level build.gradle:
buildscript {
...
dependencies {
...
classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
classpath "org.jacoco:org.jacoco.ant:$jacoco_version"
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
classpath "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
2. Force to use the same jacoco version in application's build.gradle:
configurations.all {
resolutionStrategy {
...
force "org.jacoco:org.jacoco.agent:$jacoco_version"
force "org.jacoco:org.jacoco.ant:$jacoco_version"
force "org.jacoco:org.jacoco.core:$jacoco_version"
force "org.jacoco:org.jacoco.report:$jacoco_version"
}
}
any help pls :/
el...@gmail.com <el...@gmail.com> #40
Seeing the same using AGP 7+ and Jacoco 0.8.7
ga...@google.com <ga...@google.com> #41
For everyone still having issues around Jacoco runtime, can you please file a new issue with a sample project? Thanks!
st...@gmail.com <st...@gmail.com> #42
I had the same issue using AGP 7.2.1 and Jacoco 0.8.7
Fixed it by adding this dependency:
debugImplementation 'androidx.fragment:fragment-testing:1.4.1'
ba...@gmail.com <ba...@gmail.com> #43
i had the same issue with coverage, i always got zero coverage using jacoco. i was using AGP 7.3.1 and jacoco 0.8.7. actually i had tried almost all of the solutions above. this is my jacoco file that i created.
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.7"
}
project.afterEvaluate {
if (android.hasProperty("applicationVariants")) {
android.applicationVariants.all { variant ->
createVariantCoverage(variant)
}
} else if (android.hasProperty("libraryVariants")) {
android.libraryVariants.all { variant ->
createVariantCoverage(variant)
}
}
}
ext {
excludes = [
'**/databinding/*Binding.*',
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
// butterKnife
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/Lambda$*.class',
'**/Lambda.class',
'**/*Lambda.class',
'**/*Lambda*.class',
'**/*_MembersInjector.class',
'**/Dagger*Component*.*',
'**/*Module_*Factory.class',
'**/di/module/*',
'**/*_Factory*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*Hilt*.*',
// kotlin
'**/*MapperImpl*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/*Component*.*',
'**/*BR*.*',
'**/Manifest*.*',
'**/*$Lambda$*.*',
'**/*Companion*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*Hilt*.*',
'**/*MembersInjector*.*',
'**/*_MembersInjector.class',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*',
'**/*Extensions*.*'
]
includes = [
'**/*VM.*',
'**/*ViewModel.*',
'**/*Presenter.*',
'**/*Repository.*',
'**/CommonUtils.*'
]
}
def createVariantCoverage(variant) {
def variantName = variant.name
def testTaskName = "test${variantName.capitalize()}UnitTest"
// Add unit test coverage tasks
tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "$testTaskName") {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build."
reports {
xml.enabled = false
html.enabled = true
}
def javaClasses = fileTree(dir: variant.javaCompileProvider.get().destinationDir, excludes: project.excludes, includes: project.includes)
def kotlinClasses = fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/${variantName}", excludes: project.excludes, includes: project.includes)
getClassDirectories().setFrom(files([javaClasses, kotlinClasses]))
getSourceDirectories().setFrom(files([
"${project.projectDir}/src/main/java",
"${project.projectDir}/src/${variantName}/java",
"${project.projectDir}/src/main/kotlin",
"${project.projectDir}/src/${variantName}/kotlin"
]))
getExecutionData().setFrom(files("${project.buildDir}/jacoco/${testTaskName}.exec"))
doLast {
def m = new File("${project.buildDir}/reports/jacoco/${testTaskName}Coverage/html/index.html")
.text =~ /Total[^%]*>(\d?\d?\d?%)/
if (m) {
println "Test coverage: ${m[0][1]}"
}
}
}
// Add unit test coverage verification tasks
tasks.create(name: "${testTaskName}CoverageVerification", type: JacocoCoverageVerification, dependsOn: "${testTaskName}Coverage") {
group = "Reporting"
description = "Verifies Jacoco coverage for the ${variantName.capitalize()} build."
violationRules {
rule {
limit {
minimum = 0
}
}
rule {
element = 'BUNDLE'
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.30
}
}
}
def javaClasses = fileTree(dir: variant.javaCompileProvider.get().destinationDir, excludes: project.excludes)
def kotlinClasses = fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/${variantName}", excludes: project.excludes)
getClassDirectories().setFrom(files([javaClasses, kotlinClasses]))
getSourceDirectories().setFrom(files([
"${project.projectDir}/src/main/java",
"${project.projectDir}/src/${variantName}/java",
"${project.projectDir}/src/main/kotlin",
"${project.projectDir}/src/${variantName}/kotlin"
]))
getExecutionData().setFrom(files("${project.buildDir}/jacoco/${testTaskName}.exec"))
}
}
Description
With gradle `2.14` and build:gradle plugin `2.1.2` everything builds and runs fine (with or without Instant Run enabled).
With gradle `2.14.1` and build:gradle `2.1.3` the build passes but app crashes on launch:
> NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_b0d6a23/Offline;
> caused by:
> ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_b0d6a23.Offline" on path: DexPathList[...]
However, enabling Instant Run causes the app to not crash (so does setting `testCoverageEnabled` to false). Changes the way things are loaded on the classpath?
Building from the command line I am able to use gradle `2.14.1` with both `2.1.2` and `2.1.3` of the gradle plugin. The 2.1.2 version runs fine, the 2.1.3 version crashes. This narrows it down to the gradle plugin.
Jacoco is enabled by calling `apply from` on the attached gradle script.