gpt4 book ai didi

java - Jacoco 在 Parceler 类上失败 - Android

转载 作者:行者123 更新时间:2023-11-29 19:42:35 26 4
gpt4 key购买 nike

我在 Android 上使用 Parceler 库 ( https://github.com/johncarl81/parceler )

我还使用 Jacoco 进行代码覆盖。

但是,在添加 Parceler 之后,我使用 Jacoco 的测试代码覆盖率现在失败并出现以下错误:

Caused by: java.io.FileNotFoundException: /Users/me/android/myapp/blah/app/build/intermediates/classes/demo/com/me/blah/appname/model/User$Parcelable$Creator$0.class (No such file or directory)

User类如下:

@Parcel
public class User {

@SerializedName("firstName")
String firstName;

@SerializedName("lastName")
String lastName;

@SerializedName("profileImage")
ProfileImage profileImage;

@SerializedName("username")
String username;

// empty constructor needed by the Parceler library
public User() {
}

}

我的 Jacoco 文件是这样的:

apply plugin: 'jacoco'

android {
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}

project.afterEvaluate {

android.applicationVariants.all { variant ->
def name = variant.name
def testTaskName = "test${name.capitalize()}UnitTest"

tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "$testTaskName") {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${name.capitalize()} build."

classDirectories = fileTree(
dir: "${project.buildDir}/intermediates/classes/${name}",
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*$ViewBinder*.*',
'**/*$ViewInjector*.*',
'**/Lambda$*.class',
'**/Lambda.class',
'**/*Lambda.class',
'**/*Lambda*.class',
'**/*InjectAdapter*.*',
'**/*StaticInjection*.*',
'**/*ModuleAdapter*.*']
)

sourceDirectories = files(['src/main/java'].plus(android.sourceSets[name].java.srcDirs))
executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec")

reports {
xml.enabled = true
html.enabled = true
}
}
}
}

我想知道是否需要将生成的 Parceler 文件添加到我的 Jacoco 文件中的排除列表中?如果是这样,我该怎么做?我尝试了各种变体,但似乎都不起作用。

错误提示缺少以下文件:

User$Parcelable$Creator$0.class

文件是这样生成的:

User$$Parcelable.class

谁能解释一下?

最佳答案

我只是在 jacocoAndroidCoverage.gradle 中排除它,就像这样,它现在可以工作了

def coverageSourceDirs = [
'../app/src/main/java'
]

task jacocoStagingDebugCoverageReport(type:JacocoReport, dependsOn: ["connectedStagingDebugAndroidTest"]) {
group = "Reporting"

description = "Generate Jacoco coverage reports for staging debug"
classDirectories = fileTree(
dir: '../app/build/intermediates/classes/staging/debug/com/',
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/*MembersInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*$Lambda$*.class',
'**/*Factory*.class',
'**/*$Builder*',
'**/*$Parcelable*.*',
'**/*DaggerApplicationComponent*.class',
'**/api']
)

additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files('build/outputs/code-coverage/connected/flavors/staging/coverage.ec')

reports {
xml.enabled = true
html.enabled = true
}
}

关于java - Jacoco 在 Parceler 类上失败 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38382960/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com