PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 29, 2022

[FIXED] How to fail build process upon data-binding's safeUnbox warnings

 April 29, 2022     android, data-binding, warnings     No comments   

Issue

This question explains what the "safeUnbox warning" is.

I have the following in my build.gradle:

lintOptions {
    quiet false
    abortOnError true
    warningsAsErrors true
    baseline file("lint-baseline.xml")
}

and later:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        jvmTarget = "1.8"
        allWarningsAsErrors = true
    }
}

But data-binding safeUnbox warnings don't fail the build process. The output has complains about warnings and that warnings was turned to errors:

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

But at the very end of the building process I have:

BUILD SUCCESSFUL in 46s 

Is there any way to make the whole build process unsuccessful upon "safeUnbox warning"?


Solution

I have found the solution, Yay!

Putting the following spell to the root gradle.build solves the problem.

subprojects {
    afterEvaluate {
        if (project.plugins.hasPlugin("kotlin-kapt")) {
            kapt {
                javacOptions {
                    option("-Xmaxerrs", 1000)
                    option("-Werror")
                }
            }
        }
    }
}

Also the spell increases the limit of how many errors are being logged (default value: 100) which is useful if DataBinding is used.



Answered By - Alexander Skvortsov
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing