以下是build.gradle文件
apply plugin: 'android'
apply plugin: 'jacoco'
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion "19.1.0"
jacoco {
version = '0.6.2.201302030002'
}
dexOptions {
preDexLibraries = false
}
android.enforceUniquePackageName=false
sourceSets {
androidTest {
java.srcDirs = ['\\src\\androidTest\\java', '\\src\\integTest\\
}
main {
manifest.srcFile('src/main/AndroidManifest.xml')
java.srcDir file('src/main/java')
res.srcDirs = ['src/main/res']
}
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
versionCode 35
versionName "3.4.5"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
debug {
testCoverageEnabled = true
}
}
}
任何人都知道我错过了什么。
答案 0 :(得分:2)
我正在使用此gradle
任务进行JaCoCo
次报告。
classDirectories - >排除 - 在任务中查看此行。
def coverageSourceDirs = [
'src/test/java'
]
task jacocoTestReport(type:JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
classDirectories = fileTree(
dir: "$buildDir/intermediates/classes/debug",
// Specify here files and packages which should be excluded from reports
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*']
)
reports {
xml.enabled = true
html.enabled = true
}
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files("$buildDir/jacoco/testDebug.exec")
// Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
// We iterate through the compiled .class tree and rename $$ to $.
doFirst {
new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
}