CustomLintRules


Source link: https://github.com/a11n/CustomLintRules

CustomLintRules

A basic, Gradle-based project template for writing custom Android Lint rules.

If you want to learn more about custom Lint rules please check this reference guide. If you are still looking for more details you are welcome to check this workshop on custom Lint rules.

Getting started

Step 1

Clone this repository and open it in the IDE of your choice.

git clone https://github.com/a11n/CustomLintRules.git

Step 2

In order to write your own custom Lint rules create a new class and make it extend Detector. See HelloWorldDetector for reference.

Depending on your use case you might also want to implement one of or more of Detector's interfaces:

  • JavaScanner: Specialized interface for detectors that scan Java source file parse trees
  • XmlScanner: Specialized interface for detectors that scan XML files
  • ResourceFolderScanner: Specialized interface for detectors that scan resource folders
  • ...

I recommend to have a look at the default set of detectors to get an impression of the anatomy of Detectors. [1]

Step 3

Detectors scan the development artifacts for one or more issues to report. Last but not least you need to register your custom issue(s) in the CustomIssueRegistry.

Step 4

Finally you might want to have a unit test for your custom Lint rules in place. Since end of July 2015 there is an official lint-tests library available for that purpose. [2]. HelloWorldDetectorTest demonstrates how to test custom Lint rules.

That’s it.

Application

In order to apply your custom Lint rules to your project you basically have two options.

1. Copy your rules to a specific folder

By default, Lint will look for custom Lint rules in ~/.android/lint and will consider them during analysis. To apply your custom Lint rules just assemble your rules and copy the resulting *.jar to that folder:

./gradlew clean assemble

On Unix based systems you can simply use ./buildAndInstall for your convenience.

2. Wrap your rules into an AAR bundle

A more advanced option is the new AAR format, which allows to bundle custom Lint rules [3]. You can include the resulting *.aar file into your Android application project. When executing ./gradlew lint in your Android application project your custom Lint rules will be considered automatically.

To wrap your custom Lint rules into an AAR container just execute:

./gradlew aarWrapper:assemble

You will find the AAR file in aarWrapper/build/outputs/aar/. Just copy it to the libs folder of your Android application project.

Remark

As Google points out very significant, the Lint API is not final and may change in future releases [4].

This project refers to the most recent (July 2015), stable version (24.3.0) of the Lint API [5].

Credits

Approaches used in this project have (partly) been adopted from this blog post [6]. Thank you Cheng Yang for sharing your ideas and findings.

References

  1. https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks (visited 2015-04-25)
  2. https://bintray.com/android/android-tools/com.android.tools.lint.lint-tests/24.3.0/view (visited 2015-08-01)
  3. http://tools.android.com/tech-docs/new-build-system/aar-format (visited 2015-04-25)
  4. http://tools.android.com/tips/lint/writing-a-lint-check (visited 2015-04-25)
  5. https://bintray.com/android/android-tools/com.android.tools.lint.lint-api/24.3.0/view (visited 2015-08-01)
  6. https://engineering.linkedin.com/android/writing-custom-lint-checks-gradle (visited 2015-04-25)

Resources

Work easy with Android built-in and custom content providers data + Stetho extension + Sample app.

A Material Design themed ShowcaseView for Android.

Android Device Names is a 14 kB library that transforms the device model name into something people can understand. For example, a useless SM-N910W8 becomes Samsung Galaxy Note 4.

Dumpey is an Android Debug Bridge utility tool.

FancyBackground is a tiny Android library designed to animate a set of resource Drawables. It ensures the drawables are subsampled and cached, if necessary, with heavy lifting done in the background.

Progressbar with whorl style.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes