android - 如何因数据绑定(bind)的 safeUnbox 警告而导致构建过程失败

标签 android data-binding warnings

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/

相关文章:

c# - 数据绑定(bind)、多线程和单元测试

java - Activity 之间的共享首选项

java - 启动时崩溃: "requestFeature() must be called before adding content"

c# - 如何检查 RowDataBound 中的组合 RowState 'Altering | Edit'?

c# - 如何绑定(bind)到 ComboBox 的 Selected Item 中的属性?

java - "type X[][] should explicitly be cast to Object[][] for the invocation of the varargs"

warnings - 是否可以选择显示哪个 Doxygen 警告?

Java ant 脚本不显示警告

android - 在 Android 中使用谷歌地图

android - 应用程序 (22.0.0) 和测试应用程序 (21.0.3) 的已解决版本不同