How to register AndroidLintInspectionBase in IntellijIdea Plugin


I'm creating a costum Android Lint Inspection and I need to register the inspection, to be run. Where do I need to register it?

I've already tried to register the inspection which provides the inspection inside plugin.xml file.

The actual inspection:

class HardcodedDimensionsInspection : AndroidLintInspectionBase("Hardcoded dimensions", HardcodedDimensDetector.ISSUE) {

    override fun getShortName(): String {
        return "AndroidLintHardcodedDimension"

The entry in plugin.xml file

<extensions defaultExtensionNs="com.intellij">
        <!-- Add your extensions here -->

<!--        <inspectionToolProvider implementation="JavaInspectionProvider"/>-->

        <globalInspection shortName="AndroidLintHardcodedDimension" displayName="Hardcoded dimensions"
                          enabledByDefault="true" level="WARNING"

The actual detector

class HardcodedDimensDetector : LayoutDetector() {
    override fun getApplicableAttributes(): Collection<String>? {
        return Arrays.asList(
                // Layouts

    override fun appliesTo(folderType: ResourceFolderType): Boolean {
        return (folderType == ResourceFolderType.LAYOUT ||
                folderType == ResourceFolderType.MENU ||
                folderType == ResourceFolderType.XML)

    override fun visitAttribute(context: XmlContext, attribute: Attr) {
        val value = attribute.value

    companion object {

        /** The main issue discovered by this detector  */
        val ISSUE = Issue.create(
                id = "HardcodedDimension",
                briefDescription = "Hardcoded dimens",
                explanation = """
                category = Category.I18N,
                priority = 5,
                severity = Severity.ERROR,
                implementation = Implementation(

I've expected to hit the breakpoints in any of the functions for Detector but the code is never called. Seems like my detector is not registered. Can you please point me to the missing part, is there a class where I should register my Detector?

Thank you.


The link to the full project:

Comment actions Permalink

Maybe the problem is that you use default package for your classes. Try to provide non-default package.

Comment actions Permalink

Thank you Dmitry, let me change the structure of the project and see if that will help. For now I have a workaround, but not sure it's the official one.


Android Lint has a registry with all the Issueclasses (built-in), the class is called LintIdeIssueRegistry. When it runs the Android Lint, it's looking in this registry for Issue processors. Since the list is hardcoded, we need to inject ours in the list. I'm using the following code for that:

val registry = LintIdeIssueRegistry()
val myIssue = registry.getIssue(
if (myIssue == null) {
   val list = registry.issues as MutableList<Issue>

Hopefully in future we will have a method called addIssueinside the LintIdeIssueRegistry.

Comment actions Permalink

It seems you are right, you need to add issue manually.


Please sign in to leave a comment.