JaCoCo测试覆盖率无法确定任务':createDebugAndroidTestCoverageReport'的依赖关系

时间:2017-01-24 14:44:48

标签: android android-studio gradle android-gradle gradle-experimental

执行'gradle createDebugCoverageReport'时出现以下问题:

  

出了什么问题:   无法确定任务':createDebugAndroidTestCoverageReport'的依赖关系。   java.lang.NullPointerException(无错误消息)

     

尝试:   使用--info或--debug选项运行以获得更多日志输出。

     

例外是:

org.gradle.api.GradleException: Could not determine the dependencies of task ':createDebugAndroidTestCoverageReport'.
    at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.resolve(CachingTaskDependencyResolveContext.java:67)
    at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.getDependencies(CachingTaskDependencyResolveContext.java:55)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.addToTaskGraph(DefaultTaskExecutionPlan.java:139)
    ...
Caused by: java.lang.NullPointerException
    at com.android.build.gradle.internal.variant.BaseVariantData.getJavaSourceFoldersForCoverage(BaseVariantData.java:682)
    at com.android.build.gradle.internal.coverage.JacocoReportTask$ConfigAction.lambda$execute$3(JacocoReportTask.java:335)
    at org.gradle.util.GUtil.uncheckedCall(GUtil.java:401)

我尝试了以下所有提示:How do I get a jacoco coverage report using Android gradle plugin 0.10.0 or higher?。唯一的区别是我在0.8.3版本中使用了实验性gradle插件。

buildscript {

  repositories {

      jcenter()
      maven { url 'https://plugins.gradle.org/m2/' }
  }

  dependencies {

      classpath 'com.android.tools.build:gradle-experimental:0.8.3'
  }
}

allprojects {

  repositories {

    jcenter()
  }
}

apply plugin: 'com.android.model.application'
apply plugin: "jacoco"

model {

  android {
      compileSdkVersion 25
      buildToolsVersion "25.0.2"

      defaultConfig {

        applicationId ...
        minSdkVersion.apiLevel 21
        targetSdkVersion.apiLevel 25

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }

      buildTypes {
          ...
          debug {

            debuggable true
            testCoverageEnabled true
          }
      }

      testOptions.unitTests {
           returnDefaultValues = true
      }
  }

  android.sources {
    ...
    test {
        java {
            source {
                srcDir "UnitTests"
            }
        }
    }

    androidTest {
        java {
            source {
                srcDir "AutomationTests"
            }
        }
    }
  }
}

dependencies {
  ...
}

有什么想法吗?感谢。

0 个答案:

没有答案