android jacoco coverage empty with gradle

前端 未结 8 2236
旧巷少年郎
旧巷少年郎 2021-01-12 23:39

I\'m trying to make jacoco create a code coverage report for my android test project. I have the following in build.gradle:

apply plugin: \'com.android.appli         


        
8条回答
  •  既然无缘
    2021-01-13 00:17

    I made an interesting observation. I had the same problem, with the coverage.ec File having a size of 0 bytes. I tried all the answers here as well as these ones:

    https://code.google.com/p/android/issues/detail?id=170607

    It didn't change anything. My build.gradle file has only these settings to let jacoco work:

    apply plugin: 'com.android.application'
    apply plugin: 'jacoco'
    
    android {
        ...
    buildTypes {
       ...
        debug {
            testCoverageEnabled true
        }
    }
    
    ...
    }
    

    My Android Studio Version is 1.2.2. I have the following gradle settings in "File -> Project Structure":

    • Gradle version: 2.2.1
    • Android Plugin Version: 1.2.3

    I tried to run the instrumentation tests with gradlew cC on an Motorola Moto G 4G LTE - Android 4.4.4 with correctly ran the instrumentation tests but with a coverage.ec file having 0 bytes. Today I tried another device: LG Spirit 4G LTE - Android 5.0 and now code coverage works!!! The coverage.ec file has 322 bytes and I see correct html coverage reports.

    What I think is that sometimes running gradle with gradlew cC --debug shows that coverage.ec cannot be found on the device and sometimes it shows the file being pulled. But maybe in both situations it cannot be found on the device. So choosing another device can fix the problem. Good luck!

提交回复
热议问题