5

I have got the following trouble: I have installed SonarQube and Android Plugin with "Android Lint" Quality Profile. When I execute my build.gradle script with "Android Lint" profile, sonar-runner plugin works good, but in SonarQube I can see no matching issues found, just zero.

Nevertheless, when I include another profile –not "Android Lint"– I can see a lot of issues. Also in my android SDK when apply it's own lint I can see 157 issues. What it can be?

sonar - version 3.7.4;
android plugin - version 0.1
frapen
  • 147
  • 2
  • 15
Vladimir Voitekhovski
  • 1,472
  • 5
  • 21
  • 33

3 Answers3

3

Your sonar.sources property should point to the root of AndroidManifest.xml file. E.g. if your AndroidManifest.xml file is located in src/main then your build.gradle file should contain:

sonarRunner {
    sonarProperties {
        ...
        property "sonar.sources", "src/main"
        property "sonar.profile", "Android Lint"
        ...
    }
}

If you need more paths in sonar.sources you can put them as a comma-separated list.

You can find how Sonar Android Plugin determines whether to run the analysis in its source code.

Artur Stepniewski
  • 1,401
  • 2
  • 11
  • 10
1

change your sonar properties like this:

apply plugin: "org.sonarqube"

sonarqube {

properties {

    property "sonar.projectName", "appa"

    property "sonar.projectKey", "appa_app"

    property "sonar.projectVersion", "1.0"

    property "sonar.analysis.mode", "publish"

    property "sonar.language", "java"

    property 'sonar.sourceEncoding', "UTF-8"

    property "sonar.sources", "./src/main"

    //property "sonar.exclusions", "**/*Entity.java"

  //  property "sonar.exclusions", "src/main/java/com/apparkb/model/**, **/*Entity.java"

    property "sonar.host.url", "http://192.168.21.33:9000"

    property "sonar.login", "admin"

    property "sonar.profile", "testlint"//use your quality profile instead

    property 'sonar.import_unknown_files', true

    property "sonar.android.lint.report", "./build/outputs/lint-results-debug.xml"

    property "sonar.password", "admin"

    property "sonar.java.binaries", "build/"



}
}

For creating lint-results-debug.xml you will have to run the below command on studio terminal:

./gradlew lint

It will generate the missing XML report. Be carful, it can generate a report for each build variant (Debug by default will generate build/outputs/lint-results-debug.xml). So you can call lintDebug, lintRelease... dependings on your build variant.

And change the lint properties to:

lintOptions { // set to true to turn off analysis progress reporting by lint

    quiet true

    // if true, stop the gradle build if errors are found

    abortOnError false

    // do not ignore warnings

    warningsAsErrors true
}

now if you run

./gradlew sonarqube

you will get the results shown its actually the local file report that's actually getting hosted upon the serverenter image description here

Amal p
  • 2,882
  • 4
  • 29
  • 49
  • Could you please check this https://stackoverflow.com/questions/65963755/sonarqube-for-multi-module-project-for-android – user2234 Feb 04 '21 at 05:41
0

Unfortunately if you merely point sonar.sources to src/main, you're going to get issues with all your source because you most likely don't mave minSdkVersion and targetSdkVersion set (it comes from gradle). I've tried setting my source to be some thing like:

build/intermediates/bundles/release,src/main/java

But I still get an inordinate amount of (invalid) errors due to API levels.

Eric Miles
  • 141
  • 1
  • 6
  • Were you able to find a definitive solution? – FoY Mar 23 '15 at 11:01
  • 1
    No, we're using the LINT output within Hudson/Jenkins and using Sonar for traditional, non-Android analysis. Kinda sucks but it is what it is. – Eric Miles Apr 04 '15 at 01:11