0

Ever since switching to use Jack to compile our Android application our Jacoco Code Coverage has stopped working. At first the problem was the "coverage always 0%" which I've seen mentioned by multiple others (Jacoco Test Coverage report shows 0%, android jacoco shows 0%...). However upon returning to try fixing it, I now find I can't even build the coverage tasks. After a lot of trying a number of random solutions offered across the internet I started a brand new Android Studio project and switched it to use Jack (no other changes) and it still fails with:

:main_project:createDebugAndroidTestCoverageReport FAILED

File '/path/to/project/build/intermediates/jack/striiv/debug/coverage.em' specified for property 'metadataFile' does not exist.

Here are my gradle files for the toy app.

project build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.tadams.app.jacoco"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        jackOptions.enabled = true
        jackOptions.jackInProcess = false

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled(true)
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
}

Thanks for any help you can give! In particular, I've been trying to research how the metadata file is supposed to be generated, but aside from the fact that Android is supposed to take care of it I'm having trouble understanding. Until then I'm just kind of guessing at solutions.

Edit: Remembered an important item in the Gradle logs:

:main_project:transformJackWithJackForDebugAndroidTest
Unable to find coverage plugin '/Users/tadams/Library/Android/sdk/build-tools/24.0.0/jack-coverage-plugin.jar'.  Disabling code coverage.

The .jar is absolutely in that directory, so no idea why it wouldn't see it or how to fix it.

Tbadams
  • 424
  • 1
  • 5
  • 20
  • AFAIK Jack is deprecated - quoting https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html : "cost of switching to Jack was too high" I assume that part of this cost and downsides of Jack - is complications in support of bytecode manipulation tools (among other factors) such as JaCoCo - http://trickyandroid.com/the-dark-world-of-jack-and-jill/ – Godin May 30 '17 at 19:04
  • Thanks @Godin! Yeah, unfortunately we adopted Jack shortly before they deprecated it, including refactoring to use Java 8 features like lambdas. So we're in the awkward position of deciding between refactoring again until they replace Jack with something, or living with all those downsides until Jack is replaced. Was hoping it was merely difficult to get Jacoco working, rather than impossible, but I suppose there's no guarantee of that. – Tbadams May 30 '17 at 23:11

0 Answers0