Skip to content

Lint Rules

To help developers discover potential problems at compile time and keep API usage consistent, BetterAndroid provides a built-in set of Android Lint rules.

Rule List

The following are all Lint rules currently in effect (Only effective for Kotlin language).

ui-component

Issue IDCategorySeverityPriorityBrief Description
MultipleSystemBarsControllerPropertiesCORRECTNESSERROR8Only one SystemBarsController property is allowed in a class.
ReplaceWithNotificationActionUSABILITYWARNING5Use ui-component's notification action APIs instead.
ReplaceWithNotificationComponentUSABILITYWARNING5Use ui-component's notification APIs instead.
ReplaceWithSystemBarsControllerUSABILITYWARNING5Use ui-component's SystemBarsController instead.

ui-component-adapter

Issue IDCategorySeverityPriorityBrief Description
ReplaceWithRecyclerAdapterExtensionUSABILITYWARNING5Use ui-component-adapter's RecyclerAdapter extensions instead.
ReplaceWithRecyclerViewExtensionUSABILITYWARNING5Use ui-component-adapter's RecyclerView extensions instead.

ui-extension

Issue IDCategorySeverityPriorityBrief Description
ReplaceWithActivityExtensionUSABILITYWARNING5Use ui-extension's startActivity<T>(...) instead.
ReplaceWithBackPressedExtensionUSABILITYWARNING5Use ui-extension's back pressed extensions instead.
ReplaceWithBitmapExtensionUSABILITYWARNING5Use ui-extension's bitmap decode extensions instead.
ReplaceWithCoroutinesExtensionUSABILITYWARNING5Use ui-extension's coroutine extensions instead.
ReplaceWithContextExtensionUSABILITYWARNING5Use ui-extension's context host activity extensions instead.
ReplaceWithDrawableExtensionUSABILITYWARNING5Use ui-extension's Drawable.setPadding(size) instead.
ReplaceWithFragmentExtensionUSABILITYWARNING5Use ui-extension's fragment manager extensions instead.
ReplaceWithHandleOnWindowInsetsChangedUSABILITYWARNING5Use ui-extension's handleOnWindowInsetsChanged(...) instead.
ReplaceWithLayoutInflaterExtensionUSABILITYWARNING5Use ui-extension's layoutInflater extension instead.
ReplaceWithLifecycleExtensionUSABILITYWARNING5Use ui-extension's lifecycle observer extensions instead.
ReplaceWithLifecycleOwnerExtensionUSABILITYWARNING5Use ui-extension's lifecycle owner extensions instead.
ReplaceWithRecyclerViewExtensionUSABILITYWARNING5Use ui-extension's RecyclerView.layoutManager() instead.
ReplaceWithResourcesExtensionUSABILITYWARNING5Use ui-extension's resources compat extensions instead.
ReplaceWithTextViewExtensionUSABILITYWARNING5Use ui-extension's TextView extensions instead.
ReplaceWithToastExtensionUSABILITYWARNING5Use ui-extension's toast(...) function instead of Toast.makeText(...).show().
ReplaceWithViewBindingExtensionUSABILITYWARNING5Use ui-extension's ViewBinding extensions instead.
ReplaceWithViewExtensionUSABILITYWARNING5Use ui-extension's View.kt instead.
ReplaceWithViewImeExtensionUSABILITYWARNING5Use ui-extension's showIme() or hideIme() instead.
ReplaceWithViewOutlineProviderExtensionUSABILITYWARNING5Use ui-extension's outlineProvider(...) instead.
ReplaceWithViewTooltipTextCompatExtensionUSABILITYWARNING5Use ui-extension's tooltipTextCompat instead of TooltipCompat.setTooltipText(...) or ViewCompat.setTooltipText(...).
ReplaceWithViewWalkExtensionUSABILITYWARNING5Use ui-extension's walkToRoot() or walkThroughChildren() instead.

system-extension

Issue IDCategorySeverityPriorityBrief Description
ReplaceWithAndroidVersionUSABILITYWARNING5Use system-extension's AndroidVersion instead of Build.VERSION.SDK_INT.
ReplaceWithApplicationExtensionUSABILITYWARNING5Use system-extension's application extensions instead.
ReplaceWithBroadcastExtensionUSABILITYWARNING5Use system-extension's broadcast extensions instead.
ReplaceWithClipboardExtensionUSABILITYWARNING5Use system-extension's clipboard extensions instead.
ReplaceWithIntentExtensionUSABILITYWARNING5Use system-extension's intent extensions instead.
ReplaceWithServiceExtensionUSABILITYWARNING5Use system-extension's service extensions instead.

How to Disable or Adjust Rules

If you want to disable a specific rule or change its severity, you can create a lint.xml file in the project root.

The following example

xml
<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="ReplaceWithViewExtension" severity="ignore" />
    <issue id="ReplaceWithAndroidVersion" severity="error" />
</lint>

Common severity values are:

  • ignore
  • warning
  • error
  • fatal

You can also control them directly in Gradle.

The following example

kotlin
android {
    lint {
        disable += "ReplaceWithViewExtension"
        warning += "ReplaceWithToastExtension"
        error += "ReplaceWithAndroidVersion"
    }
}

If you only want to check part of the rules, you can also use checkOnly.

The following example

kotlin
android {
    lint {
        checkOnly += setOf(
            "ReplaceWithViewExtension",
            "ReplaceWithAndroidVersion"
        )
    }
}

Feedback

Currently, most Lint detectors are completed by AI Agent, and there may still be issues, such as complex UAST scenarios that have not been tested. If you find that a Lint rule is misreporting or the Quick Fix cannot correctly fix the problem during use, you can provide an Issue ID to directly feedback to us on GitHub Issues.

If you think some rules are not reasonable and overly restrictive on the code, or if you have some new rule suggestions, please also feel free to provide feedback to us, and we will evaluate and adjust them.

Released under the Apache-2.0 License