This workshop was held at Droidcon Berlin on June 3rd, 2015.
This repository contains sources and examples covering the "Hands-on" part.
Please find the complete workshop material here.
Android Lint was introduced back in December 2011 [1]. Since then its IDE integration became better and better. Today Lint is the Android developer’s essential smart companion guaranteeing a good quality of all Android development assets. With the release of the most recent Android Studio version in January 2015 Lint features more than 200 default checks [2]. It checks for potential bugs, bad coding habits, broken conventions and much more.
However, several circumstances exist where it is necessary to extend the default set with custom Lint rules. This counts in particular for large projects with either a huge code base or big, distributed developer teams. Anyways, it is good practice to have additional team-, project- or company-wide conventions. But how to enforce them?
Although Lint is a fundamental part of the Android Developer Tools, the documentation on how to write custom Lint rules is rare [3] and deprecated [4]. Therefore, the objective of this workshop is to highlight the creation of custom Lint rules. It will showcase the usage of the most recent Lint API [5] and it will demonstrate how to write different types of rules (e.g. code-, resource-, project-structure-related). It will also present how to build custom rules with Gradle and even how to bundle them with your app project (which improves the integration into CI environments).
Furthermore, it will provide some insights of useful conventions in real-world scenarios we had to struggle with and where custom Lint rules saved a lot of time and money.
At the end, participants will be prepared and encouraged to write their own custom Lint rules.
In order to checkout and compile artifacts related to this workshop some tools are required:
- Git
- Java 7
- Gradle
- Android Studio (optional)
The workshop is structured into 4 consecutive sections.
To start, just do:
git clone https://github.com/a11n/CustomLintRulesWorkshop.git
cd CustomLintRulesWorkshop
git checkout -f section-1
In order to move from one section to another execute:
git checkout -f section-N #where N is your current section number+1
A basic project template to write custom Lint rules.
Showcase of simple detectors.
Demonstration of advanced detecting techniques.
Testing custom Lint rules.
As Google points out very significant, the Lint API is not final and may change in future releases [3].
This workshop refers to the most recent (May 2015), stable version (24.3.0-beta1) of the API [5].
- http://tools.android.com/tips/lint (visited 2015-05-01)
- http://tools.android.com/tips/lint-checks (visited 2015-05-01)
- http://tools.android.com/tips/lint/writing-a-lint-check (visited 2015-05-01)
- http://tools.android.com/tips/lint-custom-rules (visited 2015-05-01)
- https://bintray.com/android/android-tools/com.android.tools.lint.lint-api/view (visited 2015-05-28)