Android Developers: Code Review with SonarQube

Sep 15, 2015

When developing mobile apps, complexity increases as soon as you want to create something “out-of-the-box”. On large projects, quality analysis tools are life savers. SonarQube is an open source platform for continuous inspection of code quality. Today, it supports more than 25 languages, but initially, SonarQube was developed to only analyze Java code. It has been extended since, and we are lucky it has the ability to analyze Android applications, especially through a plugin : Android Lint.

SonarQube is a really great platform to start a continuous quality analysis. In projects, you will be able to monitor :

Monitoring can be done across languages, platforms, project and time, all while it’s running as a web server. Moreover it can be extended by plugins and integrated to your continuous integration flow, with Jenkins, etc.

This tutorial aims to introduce an easy way to test SonarQube locally, on your Android’s project.

Setup

In this tutorial, I introduce you to the latest version of SonarQube (5.1 at 17 June 2015) using a Linux machine. Please, be careful: with this configuration, your database will be embedded and it should be used for evaluation purposes only. According to SonarSource’s team, “The embedded database will not scale, it will not support upgrading to newer versions of SonarQube, and there is no support for migrating your data out of it into a different database engine.”

It’s really user friendly. You have major metrics on your project’s page, like duplications proportion or issues by criticality (Blocker, Critical, Major, Minor, Info). If you click these items, you can check the issues and you have clear explanations (how, where, why) along with examples of noncompliant code and suggestions for compliant solutions. It’s very useful during a stabilization phase. If your application can be built and if you have no issues -Blocker, Critical, Major, you are headed in the right direction! The next step should be unit testing, but I’ll save that for another tutorial.

2- Android Lint Testing

Now, we will set up SonarQube to be able to analyze Android’s project. Go to :

– Settings– Update Center
– Available Plugins
– Android

Add this plugin. When it’s done, go to your terminal where SonarQube was started, and shut down the process [ctrl +c]. Restart with the same command that you used earlier :