简体   繁体   中英

How do I get Jacoco coverage working in an Android project using createDebugCoverageReport?

I have the following project...

plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
    testImplementation 'junit:junit:4.13.2'
    implementation 'org.jacoco:org.jacoco.core:0.8.6'
}
android {
    compileSdk 32

    defaultConfig {
        minSdk 24
        targetSdk 32
    }
    jacoco {
        version = '0.8.6'
    }
    buildTypes {
        release {
            minifyEnabled true
        }
        debug {
            minifyEnabled false
            testCoverageEnabled true
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
}

But when I run ANDROID_HOME=/.../Android/sdk gradle clean assembleDebug createDebugCoverageReport --stacktrace I get

Unexpected SMAP line: *S KotlinDebug

The error above it seems to suggest it isn't ignoring the build folder...

java.io.IOException: Error while analyzing /.../StudioProjects/android-pure-mobile-app/.../build/tmp/kotlin-classes/debug/.../core/extensions/Enum_TypeByValueKt.class.

But I am not sure and can't figure out how to exclude directories.

How do I configure Android to generate a XML Jacoco Report?

Use jacoco 0.8.7. This version fixes parsing of SMAP for Kotlin 1.5 https://github.com/jacoco/jacoco/pull/1164

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM