Running the android lint code analysis on your jenkins server

Running the android lint code analysis on your jenkins server

Hot on the heels of yesterdays post about the cool new Jacoco plugin for Jenkins, i wanted to point out another invaluable Jenkins plugin: the Android Lint Plugin.

Android development did become a lot more robust with the introduction of the Lint tools in the Android SDK. Lint is a static code and resources analysis tool, that is similar to findbugs or pmd, in the way that is creates warnings when certain undesired patterns occur. Some of the more prominent Lint checks are:

  • Calling api methods from newer Android versions than your currently set minimum Android verision
  • Strings that are not internationalized
  • Images that are missing in different resolutions
  • Layouts that use unnecessary elements
  • And many more…

The list is rather comprehensive and i encourage everybody to dig through the list of rules to grasp the power of Lint. There are certain checks that are still missing but it is possible to extend Lint with custom rules if you choose to do so.

Although lint embeds nicely into eclipse (and also into IntelliJ) the truth about your project naturally resides on the build server. Since Lint is basically a command line tool the output can easily be gathered by the Jenkins build server for further analysis.

The Android Lint plugin for Jenkins has been developed by +Christopher Orr and has a great integration with the various Jenkins features like showing graphs, drilling down into the concrete code passages and also showing you the Lint messages of how to resolve the problem.

The only issue i have with the plugin is the inablillty to make a build fail. Even when Lint finds an issue that it marks as an “error” (like using api that is newer than your current minimum api version), the build does not fail. The error is merely recorded.

UPDATE: As Tor  Norbye pointed out in the comments you can actually make the lint analysis fail when lint detects an error. Simply add –exitcode to the lint generation. So it would not be the Lint Jenkins plugin but the analysis process that fails your build.  To run Lint simply invoke it from your Android SDKs /tools dir.

lint --exitcode --xml lint-results.xml .

UPDATE2: The rules currently contained in the Jenkins plugin are not the latest rules from the Android SDK (rev 20.0.1 currently). The Jenkins plugin needs to be updated to reflect these latest rules. Shouldn’t it be possible to use the life rules from the Android SDK directly?

None the less. Having build output from the Lint tool provided invaluable for us already and i highly encourage everybody to integrate the plugin into his own Jenkins builds (it also works on hudson btw).