Search code examples
javaandroidandroid-gradle-pluginlintandroid-lint

Creating a custom Lint Java Detector


I'm trying to create a custom rule for Lint that would be a twist on existing deprecation warning tests.

Thing is the documentation I have read so far tells me really little about how to implement a class (that I think needs to be) implementing Detector.JavaScanner

http://tools.android.com/tips/lint-custom-rules

This is a fairly general question I guess, but anyone knowledgeable of this issue, or where I could find actually useful documentation on the matter?

Thanks!


Solution

  • Documentation on this is really rare, so don't worry if you haven't found more.

    The best way to start into custom lint rule development is actually to adapt existing rules like mentioned here.

    Here are the sources of Android's default set of rules: Pick one that implements JavaScanner to see how it works.

    If you are looking for a basic, gradle-based, project template for your custom rules, please take a look at one custom rule I have created. Just replace the HardcodedValueDetector with your detector and reference it in the CustomIssuesRegistry.

    One last remark: I hold a workshop at Droidcon 2015 in Berlin, where I elaborated on how to write custom lint rules. One part was on JavaScanners. I am going to publish all sources after that workshop.