Step 42: Keep the Build Clean ~ Johannes Brodwall

Birat Rai
2 min readJan 3, 2018

--

This is the 42nd Step towards gaining the Programming Enlightenment series. If you didn’t learn the 41st Step, read it.

It comes as a no surprise that Android Studio has lint warnings in our project. Whenever we build our project, we can see the above list of warnings.

Most of them we ignore. The reasons may be:

  • Missing translations (and unused translations)
  • Unused resources
  • Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
  • Icon problems (like missing densities, duplicate icons, wrong sizes, etc)

Why keep the build clean?

If you keep cluttering the warning, some important problems will miss out. You will only find it out much later when it crashes or some weird stuff happens.

Make Lint warnings useful?

  • Break build on lint warnings by adding configuration to gradle:
lintOptions {
warningsAsErrors true
}
  • Create a custom configuration file for lint to separate what should break and rest to ignore.
lintOptions {
lintConfig file("lint.xml")
}
// The lint.xml might look like this
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Changes the severity of these to "error" for getting to a warning-free build -->
<issue id="UnusedResources" severity="error"/>
<!-- Disable the given check in this project -->
<issue id="IconMissingDensityFolder" severity="ignore" />
</lint>

How to run lint in Android Studio?

  • Run from Command line:
./gradlew lint
  • Run from IDE:
From the menu bar, select Analyze > Inspect Code.

TL;DR Don’t ignore the lint warnings. Make sure the build is always clean. Get rid of the unnecessary noise by suppressing them.

Go to the series.

Go to 41st Step

Go to the 43rd Step.

References:

--

--

Birat Rai
Birat Rai

No responses yet