Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't add different class with same name" in an Android project with the JACOCO engine #78

Closed
cristan opened this issue Nov 26, 2021 · 7 comments

Comments

@cristan
Copy link

cristan commented Nov 26, 2021

Steps to reproduce (or use the attached project)

  • Create an empty Android Project in Android studio.
  • Add the following after the buildscript block in the root build.gradle
plugins {
    id 'org.jetbrains.kotlinx.kover' version '0.4.2'
}
  • Add the following in app/build.gradle:
kover {
    coverageEngine.set(kotlinx.kover.api.CoverageEngine.JACOCO)
}
  • Change the repositoriesMode to RepositoriesMode.PREFER_SETTINGS (because this change isn't in 0.4.2 yet)

  • Add this class

class Main {
    fun helloWorld() = "Hello ${world()}!"

    fun greet(s: String) = "Hello $s!"

    inline fun world() = "world"
}
  • Change ExampleUnitTest:
class ExampleUnitTest {
    @Test
    fun testHello() {
        val m = Main()
        assert(m.greet(m.world()).contains("world"))
    }
}
  • Clean the project
  • Run the gradle tasks koverVerify koverHtmlReport

You then see this error:

Execution failed for task ':app:koverHtmlReport'.
> Error while creating report

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:koverHtmlReport'.
Caused by: : Error while creating report
...
Caused by: java.io.IOException: Error while analyzing /Users/cristan/AndroidStudioProjects/TestKoverAndroidProject/app/build/tmp/kotlin-classes/debug/com/example/testkoverandroidproject/Main.class.
	at org.jacoco.core.analysis.Analyzer.analyzerError(Analyzer.java:162)
	at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:134)
	at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:157)
	at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:193)
	at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:226)
	at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:221)
	at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:221)
	at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:221)
	at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:221)
	at org.jacoco.ant.ReportTask.createBundle(ReportTask.java:570)
	at org.jacoco.ant.ReportTask.createReport(ReportTask.java:545)
	at org.jacoco.ant.ReportTask.execute(ReportTask.java:496)
	... 132 more
Caused by: java.lang.IllegalStateException: Can't add different class with same name: com/example/testkoverandroidproject/Main
	at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:106)
	at org.jacoco.core.analysis.Analyzer$1.visitEnd(Analyzer.java:99)
	at org.objectweb.asm.ClassVisitor.visitEnd(ClassVisitor.java:377)
	at org.jacoco.core.internal.flow.ClassProbesAdapter.visitEnd(ClassProbesAdapter.java:100)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:725)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:401)
	at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:116)
	at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:132)
	... 142 more
@shanshin
Copy link
Collaborator

Related to #11

@esafirm
Copy link

esafirm commented Jan 18, 2022

I also got this error while using the Jacoco engine, could you elaborate on what's happening here since #11 is not really explaining anything. Thanks!

@shanshin
Copy link
Collaborator

@esafirm, if you are writing an Android project, you probably have classes with the same full qualified name in different flavors (or build types).
These classes fall into the classpath of the JaCoCo reporter and report generation fails due to ambiguity.

API for limiting flavors is still in development (#18)

@ptsiogas
Copy link

I run into the same issue today. With Kover version 0.3.0 there was no issue though.
Are there any plans on fixing/work around this issue?

@shanshin
Copy link
Collaborator

shanshin commented Apr 8, 2022

@ptsiogas, the issue is serious and lies in an unsuitable API for Android.
It will be solved comprehensively and using a separate API for Android and updating reports to support flavours.

As a workaround, you can try to exclude a repeating class from instrumentation.

@shanshin
Copy link
Collaborator

shanshin commented Apr 8, 2022

Relates #18

@shanshin
Copy link
Collaborator

Closed as a part of #18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants