Lint 静态检查规范
为了帮助开发者在编译期及时发现潜在问题、规范 API 调用,
BetterAndroid内置了一套 Android Lint 规则。
规则列表
以下是目前生效的所有 Lint 规则列表。
ui-component
| Issue ID | 类别 | 级别 | 优先级 | 简要描述 |
|---|---|---|---|---|
| MultipleSystemBarsControllerProperties | CORRECTNESS | ERROR | 8 | Only one SystemBarsController property is allowed in a class. |
| ReplaceWithNotificationComponent | USABILITY | WARNING | 5 | Use ui-component's notification APIs instead. |
| ReplaceWithSystemBarsController | USABILITY | WARNING | 5 | Use ui-component's SystemBarsController instead. |
ui-component-adapter
| Issue ID | 类别 | 级别 | 优先级 | 简要描述 |
|---|---|---|---|---|
| ReplaceWithRecyclerAdapterExtension | USABILITY | WARNING | 5 | Use ui-component-adapter's RecyclerAdapter extensions instead. |
| ReplaceWithRecyclerViewExtension | USABILITY | WARNING | 5 | Use ui-component-adapter's RecyclerView extensions instead. |
ui-extension
| Issue ID | 类别 | 级别 | 优先级 | 简要描述 |
|---|---|---|---|---|
| ReplaceWithActivityExtension | USABILITY | WARNING | 5 | Use ui-extension's startActivity<T>(...) instead. |
| ReplaceWithBackPressedExtension | USABILITY | WARNING | 5 | Use ui-extension's back pressed extensions instead. |
| ReplaceWithBitmapExtension | USABILITY | WARNING | 5 | Use ui-extension's bitmap decode extensions instead. |
| ReplaceWithCoroutinesExtension | USABILITY | WARNING | 5 | Use ui-extension's coroutine extensions instead. |
| ReplaceWithContextExtension | USABILITY | WARNING | 5 | Use ui-extension's context host activity extensions instead. |
| ReplaceWithDrawableExtension | USABILITY | WARNING | 5 | Use ui-extension's Drawable.setPadding(size) instead. |
| ReplaceWithFragmentExtension | USABILITY | WARNING | 5 | Use ui-extension's fragment manager extensions instead. |
| ReplaceWithHandleOnWindowInsetsChanged | USABILITY | WARNING | 5 | Use ui-extension's handleOnWindowInsetsChanged(...) instead. |
| ReplaceWithLayoutInflaterExtension | USABILITY | WARNING | 5 | Use ui-extension's layoutInflater extension instead. |
| ReplaceWithLifecycleExtension | USABILITY | WARNING | 5 | Use ui-extension's lifecycle observer extensions instead. |
| ReplaceWithLifecycleOwnerExtension | USABILITY | WARNING | 5 | Use ui-extension's lifecycle owner extensions instead. |
| ReplaceWithRecyclerViewExtension | USABILITY | WARNING | 5 | Use ui-extension's RecyclerView.layoutManager() instead. |
| ReplaceWithResourcesExtension | USABILITY | WARNING | 5 | Use ui-extension's resources compat extensions instead. |
| ReplaceWithTextViewExtension | USABILITY | WARNING | 5 | Use ui-extension's TextView extensions instead. |
| ReplaceWithToastExtension | USABILITY | WARNING | 5 | Use ui-extension's toast(...) function instead of Toast.makeText(...).show(). |
| ReplaceWithViewBindingExtension | USABILITY | WARNING | 5 | Use ui-extension's ViewBinding extensions instead. |
| ReplaceWithViewExtension | USABILITY | WARNING | 5 | Use ui-extension's View.kt instead. |
| ReplaceWithViewImeExtension | USABILITY | WARNING | 5 | Use ui-extension's showIme() or hideIme() instead. |
| ReplaceWithViewOutlineProviderExtension | USABILITY | WARNING | 5 | Use ui-extension's outlineProvider(...) instead. |
| ReplaceWithViewTooltipTextCompatExtension | USABILITY | WARNING | 5 | Use ui-extension's tooltipTextCompat instead of TooltipCompat.setTooltipText(...) or ViewCompat.setTooltipText(...). |
| ReplaceWithViewWalkExtension | USABILITY | WARNING | 5 | Use ui-extension's walkToRoot() or walkThroughChildren() instead. |
system-extension
| Issue ID | 类别 | 级别 | 优先级 | 简要描述 |
|---|---|---|---|---|
| ReplaceWithAndroidVersion | USABILITY | WARNING | 5 | Use system-extension's AndroidVersion instead of Build.VERSION.SDK_INT. |
| ReplaceWithApplicationExtension | USABILITY | WARNING | 5 | Use system-extension's application extensions instead. |
| ReplaceWithBroadcastExtension | USABILITY | WARNING | 5 | Use system-extension's broadcast extensions instead. |
| ReplaceWithClipboardExtension | USABILITY | WARNING | 5 | Use system-extension's clipboard extensions instead. |
| ReplaceWithIntentExtension | USABILITY | WARNING | 5 | Use system-extension's intent extensions instead. |
| ReplaceWithServiceExtension | USABILITY | WARNING | 5 | Use system-extension's service extensions instead. |
如何关闭或调整规则
如果你想关闭某一条规则,或将某一条规则调整为其它级别,可以在项目根目录创建 lint.xml。
示例如下
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="ReplaceWithViewExtension" severity="ignore" />
<issue id="ReplaceWithAndroidVersion" severity="error" />
</lint>
其中 severity 常用值如下:
ignorewarningerrorfatal
你也可以直接在 Gradle 中进行控制。
示例如下
android {
lint {
disable += "ReplaceWithViewExtension"
warning += "ReplaceWithToastExtension"
error += "ReplaceWithAndroidVersion"
}
}
当你只想检查部分规则时,也可以使用 checkOnly。
示例如下
android {
lint {
checkOnly += setOf(
"ReplaceWithViewExtension",
"ReplaceWithAndroidVersion"
)
}
}
问题反馈
目前大部分 Lint 检测器均由 AI Agent 代为完成,可能仍然存在问题,例如尚未测试过的复杂 UAST 语法树场景。如果你在使用过程中发现了 Lint 规则出现了误报或 Quick Fix 无法正确修复问题,可以通过提供 Issue ID 在 GitHub Issues 直接向我们反馈。
如果你认为一些规则不够合理出现过于约束代码的情况,或者你有一些新的规则建议,也欢迎向我们反馈,我们会进行评估和调整。
