0

描述

摇篮 5.6.4

安卓工作室 3.6.3

问题

在目录下的一个文件中androidTest,有这么一行代码,得到了ClassNotFoundException.

Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");

项目结构

.
├── build.gradle
├── subproject.main (app)
       ├── src
       ├── ...
       └── build.gradle
├── subproject1
├── subproject2
 ...

构建.gradle

./build.gradle

buildscript {
    ext.jacocoVersion="0.8.2"
    ...
    dependencies {
         ...
         classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
    }
}

subproject.main/build.gradle

...
dependencies {
     ...
     jacocoAnt 'org.jacoco:org.jacoco.ant:0.8.1:nodeps'
}

apply plugin: 'jacoco'
...

据此,_

| org.jacoco | org.jacoco.ant | 节点 | Ant 任务(包括所有依赖项) |

梯度依赖:

查看依赖项subproject.main

 $ ./gradlew app:dependencies | grep jacoco

输出是

jacocoTestReport_test
jacocoAgent - The Jacoco agent to use to get coverage data.
\--- org.jacoco:org.jacoco.agent:0.8.2
jacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.8.1
     +--- org.jacoco:org.jacoco.core:0.8.1
     +--- org.jacoco:org.jacoco.report:0.8.1
     |    \--- org.jacoco:org.jacoco.core:0.8.1 (*)
     \--- org.jacoco:org.jacoco.agent:0.8.1
jacocoRuntime

ls ~/.gradle/caches/modules-2/files-2.1

 org.jacoco
 ├── org.jacoco.core
 └── org.jacoco.report
4

1 回答 1

0

最后我得到了它!这是因为 的默认值testCoverageEnabled如下false配置所示。无条件设置就行了。testCoverageEnabled true

buildTypes {
    debug {
       ...
       if (isFromServer()) {
           testCoverageEnabled true
       }
    }
}
于 2021-06-30T12:46:53.457 回答