A while ago i tried adding lint to my android studio project by adding a lint.xml file at the app module and adding the following lintOptions:
lintOptions {
abortOnError true
checkReleaseBuilds true
lintConfig file("lint.xml")
}
Everything was working fine, debug builds were failing when there were lint errors and passing otherwise. I did not incorporate the changes into the project though and i recently returned to those changes to find that builds are no longer failing on lint errors. I cant seem to find the changes made in the project during that time that caused this. Release builds are still failing on lint errors as expected.
from what i can gather the lint task is supposed to run by default but i am not seeing it as part of the tasks run when i build
additional info that might help:
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!--The given layout_param is not defined for the given layout, meaning it has no
effect.-->
<issue id="ObsoleteLayoutParam" severity="error" />
<!--A layout that has no children or no background can often be removed-->
<issue id="UselessLeaf" severity="error" />
<issue id="HardcodedText" severity="error" />
<issue id="UnusedResources" severity="error" />
<!--AdapterViews such as ListViews must be configured with data from Java code,
such as a ListAdapter.-->
<issue id="AdapterViewChildren" severity="error" />
<!--Missing commit() on SharedPreference editor-->
<issue id="CommitPrefEdits" severity="error" />
<!--looks for cases where you have cut & pasted calls to
findViewById but have forgotten to update the R.id field-->
<issue id="CutPasteId" severity="error" />
<!--Calling String#toLowerCase() or #toUpperCase() without specifying an explicit
locale is a common source of bugs.-->
<issue id="DefaultLocale" severity="error" />
<!--Implied locale in date format-->
<issue id="SimpleDateFormat" severity="error" />
<!--Incorrect order of elements in manifest-->
<issue id="ManifestOrder" severity="error" />
<!--Using STRING instead of TEXT-->
<issue id="SQLiteString" severity="error" />
<!--Memory allocations within drawing code-->
<issue id="DrawAllocation" severity="error" />
<!--Handler is declared as an inner class, it may prevent the outer
class from being garbage collected.-->
<issue id="HandlerLeak" severity="error" />
<!--Ellipsis string can be replaced with ellipsis character-->
<issue id="TypographyEllipsis" severity="error" />
<!--ScrollViews can have only one child-->
<issue id="ScrollViewCount" severity="error" />
<!--FragmentTransaction, you typically need to commit it as well-->
<issue id="CommitTransaction" severity="error" />
<!--A scrolling widget such as a ScrollView should not contain any nested
scrolling widgets since this has various usability issues-->
<issue id="NestedScrolling" severity="error" />
<!--ScrollView children must set their layout_width or layout_height attributes to
wrap_content-->
<issue id="ScrollViewSize" severity="error" />
<!--Using Wrong AppCompat Method-->
<issue id="AppCompatMethod" severity="error" />
<!--Some methods have no side effects, an calling them without doing something
without the result is suspicious.-->
<issue id="CheckResult" severity="error" />
<!--Duplicate ids across layouts combined with include tags-->
<issue id="DuplicateIncludedIds" severity="error" />
<!--This check ensures that a layout resource which is defined in multiple
resource folders, specifies the same set of widgets.-->
<issue id="InconsistentLayout" severity="error" />
<!--Wrong locale name-->
<issue id="LocaleFolder" severity="error" />
<!--Target SDK attribute is not targeting latest version-->
<issue id="OldTargetApi" severity="error" />
<!--Frequent alarms are bad for battery life.-->
<issue id="ShortAlarm" severity="error" />
<!--Using system app permission-->
<issue id="ProtectedPermissions" severity="ignore" />
<!--Package not included in Android-->
<issue id="InvalidPackage" severity="ignore" />
</lint>
@SuppressLint("NewApi") Just invoke the quickfix for the warning, and one of the options will be to ignore the issue with an annotation; this will annotate either the local declaration, or the method, or the class, or the field, depending on the location of the error.
What Is Linting? Linting is the automated checking of your source code for programmatic and stylistic errors. This is done by using a lint tool (otherwise known as linter). A lint tool is a basic static code analyzer. The term linting originally comes from a Unix utility for C.
In many cases, lint warns you about incorrect, error-prone, or nonstandard code that the compiler does not necessarily flag. The lint program issues every error and warning message produced by the C compiler. It also issues warnings about potential bugs and portability problems.
Found a solution on Run lint when building android studio projects. basically you make the assemble task depend on the the lint task to force it to run:
applicationVariants.all { variant ->
variant.outputs.each { output ->
def lintTask = tasks["lint${variant.name.capitalize()}"]
output.assemble.dependsOn lintTask
}
}
For Library projects -
libraryVariants.all { variant ->
variant.outputs.each { output ->
def lintTask = tasks["lint${variant.name.capitalize()}"]
tasks["bundle${variant.name.capitalize()}"].dependsOn lintTask
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With