Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar, Gradle and Android returns 0 issue

The problem

I have an Android project that compiles and works correctly. It's "managed" by Gradle and continuously built with Jenkins. I would like to analyze my code quality with Sonar.

The Sonar analysis is made with the sonarRunner Gradle task. The problem is that Sonar still telling me that there is "0 issue"... (I can ensure you that there are errors... I add one myself to be sure...). However, it gives me other information like : number of lines of code, number of classes, comments and documentation percentages, duplication percentage, complexity... It's like Android Lint was not running.

What I tried

lint works like a charm... :

Ran lint on variant armRelease: 153 issues found

Ran lint on variant armDebug: 153 issues found

Ran lint on variant x86Debug: 153 issues found

Ran lint on variant x86Release: 153 issues found

I tried a lot of thing that I read over the Internet and SO :

  • Publishing Lint results to Sonar using Gradle
  • http://www.gradle.org/docs/current/userguide/sonar_runner_plugin.html
  • https://github.com/stephanenicolas/Quality-Tools-for-Android/blob/master/build.gradle

I had some different errors like "Class 'android/content/res/Resources' is not accessible through the ClassLoader." or something else, but I never was able to have a correct report).

The details

Structure of the project

- myProjectName
    | build
    | libs
    | src
        | debug
        | main
            | assets
            | java
                | com.myPackage...
            | jniLibs
            | res
            | AndroidManifest.xml
        | release
    | build.gradle
    | gradle.properties
    | settings.gradle

settings.gradle

Empty


gradle.properties

Empty


build.gradle (useless parts removed)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
    }
}

/**********************************
 * Plugins declarations
 **********************************/
apply plugin: 'com.android.application'
apply plugin: "sonar-runner"

/**********************************
 * Sonar Runner configuration
 **********************************/
sonarRunner {
    sonarProperties {
        property "sonar.host.url", "http://pic.url/sonar"
        property "sonar.jdbc.url", "jdbc:mysql://pic.url/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true"
        property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
        property "sonar.jdbc.username", "*****"
        property "sonar.jdbc.password", "*****"

        property "sonar.language", "java"
        property "sonar.profile", "MyCompany Android"
        property "sonar.projectVersion", "1.0"
        property "sonar.analysis.mode", "analysis"

        properties["sonar.sources"] = android.sourceSets.main.java.srcDirs
        properties["sonar.binaries"] = [file("build/intermediates/classes/x86/debug")]
    }
}

/**********************************
 * Android configuration
 **********************************/
android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.myPackage..."
        minSdkVersion 14
        targetSdkVersion 16
        versionCode 1
        versionName "1.0"
    }

    lintOptions {
        abortOnError false
    }
}

As I tried a lot of thing, I don't any clue on what to try next. Please ask in comments if you need more information.

Last information :

  • Sonar 3.7
  • Gradle 1.12
  • JVM 1.8.0_20 Oracle
  • OS : Linux Fedora 20

EDIT

gradle sonarRunner log (asked in comments) : http://pastebin.com/uJwqpAkY

(all the '***' are here to hide company names, everything is normal :))

like image 611
mithrop Avatar asked Oct 21 '22 00:10

mithrop


1 Answers

It seems that the AndroidLintSensor is not executed during your analysis. (otherwise you would see the line Sensor AndroidLintSensor... somewhere in your log.

This could be due to many reasons : Does your profile includes android rules ? Your project must have java files and an android manifest located in your base directory or your source directory to trigger the execution of the sensor (which will execute android lint).

(if you are curious, here is the part of the code that will trigger the execution of the sensor : AndroidLintSensor.java )

like image 86
benzonico Avatar answered Nov 14 '22 05:11

benzonico