This question解释什么是“safeUnbox 警告”。
我的 build.gradle 中有以下内容:
lintOptions {
quiet false
abortOnError true
warningsAsErrors true
baseline file("lint-baseline.xml")
}
及以后:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
jvmTarget = "1.8"
allWarningsAsErrors = true
}
}
但是数据绑定(bind) safeUnbox 警告不会使构建过程失败。输出提示警告,并且警告已转变为错误:
w: warning: viewModel.doorsState.getValue().first is a boxed field but needs to be un-boxed to execute android:text. This may cause NPE so Data Binding will safely unbox it. You can change the expression and explicitly wrap viewModel.doorsState.getValue().first with safeUnbox() to prevent the warning
file:///.../app/src/debug/res/layout/activity_car_connection_debug.xml Line:75
e: warnings found and -Werror specified
但是在构建过程的最后我有:
BUILD SUCCESSFUL in 46s
有没有办法让整个构建过程在“safeUnbox警告”时失败?
最佳答案
我找到了解决方案,耶!
将以下咒语放入根 gradle.build
即可解决问题。
subprojects {
afterEvaluate {
if (project.plugins.hasPlugin("kotlin-kapt")) {
kapt {
javacOptions {
option("-Xmaxerrs", 1000)
option("-Werror")
}
}
}
}
}
该咒语还增加了记录错误数量的限制(默认值:100),如果使用数据绑定(bind),这将非常有用。
关于android - 如何因数据绑定(bind)的 safeUnbox 警告而导致构建过程失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53135618/