Android Sonar properties for report paths

Hi,

I have trouble concerning the setting of “sonar.androidLint.reportPaths” and “sonar.coverage.jacoco.xmlReportPaths” on the sonar plugin for Gradle. It seems that those paths aren’t took in account when Sonar is running.

Here it is my Gradle file (in Kotlin) :

plugins {

    id("org.sonarqube") version "5.1.0.4882"
}

sonar {

    setAndroidVariant("karosBeta")

    properties {
        property("sonar.projectKey", "xxxxxxxxxxxxx")
        property("sonar.organization", "xxxxxxxxxxxx")
        property("sonar.host.url", "https://sonarcloud.io")
        property("sonar.projectVersion", "${versionsProperties["karosVersionName"]}")
        property("sonar.androidLint.reportPaths", "app/build/reports/lint-results-karosBeta.xml")
        property("sonar.coverage.jacoco.xmlReportPaths", "app/build/reports/jacoco/jacoco-xml-report.xml")
    }
}

But when I run Sonar, I got this error for Android Linter :

Unable to import Android Lint report file(s):
- /home/aurelien/Dev/Android/karos-android/app/build/reports/lint-results-karosDev.xml
The report file(s) can not be found. Check that the property 'sonar.androidLint.reportPaths' is correctly configured.

And I got this error for JaCoCo report :

No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='app/build/reports/jacoco/jacoco-xml-report.xml'. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml

Both files exists, their paths is correct. My comprehension of this issue is that Sonar don’t read the properties set for paths. Or maybe I miss something but I don’t know what ?

Hi,

Welcome to the community and thanks for this report!

Could you provide a full --info analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hi,

You can found my full logs here :

After reading those logs, it seems that, even if error messages, files are found ?! :roll_eyes:

But, on SonarCloud, I don’t see any results… I really don’t understand what append…

Hi,

Thanks for the log.

It’s not clear to me what’s happening. Typically when we see log lines like this:

No input file found for /home/aurelien/Dev/Android/karos-android/app/src/karos/AndroidManifest.xml. No android lint issues will be imported on this file.
No input file found for /home/aurelien/Dev/Android/karos-android/app/src/main/java/fr/karos/karos/app/ui/views/MapMaskView.kt. No android lint issues will be imported on this file.

it’s because the paths in the report don’t match the paths analysis is seeing. But based on the earlier part of the log,

Indexing files of module 'app'
  Base dir: /home/aurelien/Dev/Android/karos-android/app
  Source paths: src/main/AndroidManifest.xml, src/main/java, src/main/res, sr...
  Test paths: src/test/java, src/androidTest/java
  Excluded sources: **/build-wrapper-dump.json

I would expect the paths to match up.

Can you double-check some of these paths to make sure the files actually exist at those locations?

As a side note, I see some /res paths in the list, and those won’t be picked up unless you enable that by setting sonar.gradle.scanAll to True.

Regarding JaCoCo, I’m not sure what’s going on there either, but we try to keep it to one topic per thread. Otherwise it can get messy, fast. Since we’re not coming to an obvious solution that wraps up both topics, let’s stick to AndroidLint for now.

 
Ann

Where we can see No input file found. The file exist. And like you say, the paths match up with the base dir logs. So, I don’t understand what I miss.
I try sonar.gradle.scanAll but it changes nothing.

Hi,

I’m not sure where to go from here, so I’m going to flag this for more expert eyes.

 
Ann

1 Like

Hello @aguillard,

Could you provide a small reproducer for the investigation to help speed up the investigation? By a reproducer, I mean a zip with a mini version of the project structure with the reports and their configuration.

Cheers,
Angelo

Hi @angelo.buono, my project is really heavy and I can’t share source code. What file do you need exactly ?

For info, I want to use a special build variant for Sonar which is : karosBeta (karos = flavor ; beta = build type)

Is it a problem with Sonar to use build variant ? I have to set on Sonar configuration setAndroidVariant("karosBeta") but it seems to change nothing.

Thanks

Hello @aguillard,

You don’t need to share any source code from your project. It is sufficient to create a new small project in which you experience the same issue so we can use it as a reference to investigate what is going on. Would you be able to provide it?

Meanwhile, you can try the following things:

  1. Comment out the configuration of sonar.androidLint.reportPaths and sonar.coverage.jacoco.xmlReportPaths in the Gradle build file. Once the variant is specified the plugin should be able to correctly find the reports. Let’s try if it works.
  2. Make sure that the variant name is correct and there are no typos.
  3. Generate the list of properties generated by the plugin by using the property sonar.scanner.dumpToFile=path\to\file. Please provide the output so we can investigate if the properties configured are correctly applied.

Also, what is the version of the Android plugin you’re using?

Hi @angelo.buono,

I have tried to comment sonar.androidLint.reportPaths and sonar.coverage.jacoco.xmlReportPaths but Sonar scanner doesn’t find automatically my files.

For sur the variant name from setAndroidVariant("karosBeta") is correct.

And finally, here it is my Sonar scanner dump file :

What I see on this dump file, it’s there are several path files because of app module. Maybe my issue is related to this ?
In sonar.androidLint.reportPaths, we can find the file that I have set on Sonar property.
And in \:app.sonar.androidLint.reportPaths , we find the automatic value and I think Sonar search on this path instead of mine ?

Maybe I need to configure something on the gradle file of the app module ?

Thanks

Hi again @angelo.buono,

I finally found the issue ! It’s was a problem with the app module of Android. The solution is to configure Sonar with subprojects configuration like this :

sonar {

    setAndroidVariant("karosBeta")

    properties {
        property("sonar.projectKey", "Karos-mobility_karos-android")
        property("sonar.organization", "karos")
        property("sonar.host.url", "https://sonarcloud.io")
        property("sonar.projectVersion", "${versionsProperties["karosVersionName"]}")
    }
}

subprojects {

    sonar {

        properties {
            property("sonar.androidLint.reportPaths", "build/reports/lint-results-karosBeta.xml")
            property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/kover/reportKarosBeta.xml")
        }
    }
}
2 Likes

Hello @aguillard, I’m happy that you find a solution! Thank you for updating us.

May I ask you to share more details about the problem with the app module? It will help us to gather more knowledge about Android projects and improve the documentation.

Cheers,
Angelo