Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analyzing Android Project with Lint and SonarQube

I really got an 'overflow' trying to make these things to work together. I followed instruction from here: http://docs.sonarqube.org/display/PLUG/Android+Lint+Plugin and finally got a SonarQube 5.1.1 server with Android Lint plugin 1.1 installed. Then I configured my multi-module Gradle build to work with SonarQube plugin: see code fragment from root config below.

plugins {     id 'org.sonarqube' version '1.0' }  sonarqube {     properties {          property 'sonar.host.url', 'sonarqube-server:9000'         property 'sonar.jdbc.url', 'jdbc:mysql://sonarqube-db:3306/sonar?useUnicode=true&characterEncoding=utf8'         property 'sonar.jdbc.driverClassName', 'com.mysql.jdbc.Driver'         property 'sonar.jdbc.username', 'sonar'         property 'sonar.jdbc.password', 'sonar'         property 'sonar.sourceEncoding', 'UTF-8'         property 'sonar.login', 'admin'         property 'sonar.password', 'admin'          property 'sonar.profile', 'Android Lint'          property 'sonar.import_unknown_files', true         property 'sonar.android.lint.report', 'build/outputs/lint-results.xml'     } } 

And after that I ran lint sonarqubetask to execute the analysis. As a result I got a bulk of Lint errors regarding 'retrolambda' project (java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression), which is quite normal, and lint-results.xml (accompanied with HTML version) files per each module containing descriptions of issues discovered. The report said that there were 8 errors and 434 warnings found. But things went wrong when sonarqube plugin tried to upload the results to SonarQube server. The log was full of 'Unable to find file' and 'Unable to find rule' messages. And when the processing was over, then there were no issues reported for my project on SonarQube server.

And I am wondering, what did went wrong? I checked the paths, and all files were there. I looked through all discussions I could reach, and it seems like my config is correct and I do everything right. Does anybody have any clue, what I missed and what needs to be checked? Any suggestions or ideas are welcome.

I will be also happy if there is a way to import lint data using external SonarQube Runner, since this tool seems to be more predictable and stable then a Gradle plugin.

like image 962
sviklim Avatar asked Aug 12 '15 15:08

sviklim


People also ask

Does SonarQube do Linting?

SonarLint catches issues right in your IDE while SonarQube analyzes pull requests and branches. The combination forms a continuous code quality analysis solution that keeps your codebase clean. You'll spend less time reviewing code issues and more time on code logic and solving interesting problems!

How do I use SonarQube on Android?

Access the running SonarQube instance, in my case, I'm running locally on port 9000, so I can just access it in http://localhost:9000,then login with admin as user and password. This assumes that you have already created an Android Studio project. We need to add the sonar scanner plugin and jacoco for the tests.

How do you integrate SonarLint with SonarQube?

In Intellij — Go to File >> Plugins >> Type 'SonarLint' >> Install and Restart IDE. (2) we can choose the SonarQube rules. → To integrate SonarQube(server) and SonarLint in our IDE and run SonarQube code inspection rules per class to give results quickly. Add the sonarQube connection binding.

What is lint option in Android?

Android Studio provides a code scanning tool called lint that can help you to identify and correct problems with the structural quality of your code without having to execute the app or write test cases.


2 Answers

I had success with a multimodule android project. Since the complete build files take too much space I show the relevant parts here only.

In the parent project's build.gradle I set:

buildscript {     ...     dependencies { classpath 'com.android.tools.build:gradle:1.5.0'     ... } plugins { id "org.sonarqube" version "1.1" } 

In the app project (and any other children) I set:

sonarqube {     properties {         property "sonar.profile", "Android Lint"         property "sonar.sources", "./src/main/java"     } } 

That was the minimum setup for SonarQube plugin to start analyzing the projects.

like image 51
JanPl Avatar answered Sep 16 '22 11:09

JanPl


Your gradle settings seems fine, have you installed Android plugin on SonarQube server.

I don't see that step on your question, if not goto Settings->System->Update Center and install Android plugin.

enter image description here

Once that is installed you need to restart your SonarQube server and rerun sonar-runner.

like image 37
Abhishek Patidar Avatar answered Sep 20 '22 11:09

Abhishek Patidar