Laurent Cudini
Laurent Cudini

Reputation: 81

Android classes not found during sonar analysis

I trying to set a sonar analysis on an android project

The analysis is done with version 4.3 of sonarQube trough sonar-runner, android-plugin install, ANDROID_HOME env variable is set on /path/to/android/sdk, the build is done with ant without any problems

the execution run well but i have tons of error messages :

14:23:46.563 ERROR - Class not found: android.content.UriMatcher
14:23:46.563 ERROR - Class not found: android.net.Uri
14:23:46.563 ERROR - Class not found: android.database.sqlite.SQLiteDatabase
14:23:46.568 ERROR - Class not found: android.provider.BaseColumns
14:23:46.757 ERROR - Class not found: android.net.Uri
14:23:46.829 ERROR - Class not found: android.content.ContentProvider
14:23:46.829 ERROR - Class not found: android.net.Uri
14:23:46.830 ERROR - Class not found: android.database.sqlite.SQLiteDatabase
14:23:46.830 ERROR - Class not found: android.content.Context
...

My sonar-project.propeties :

sonar.projectKey=Client-Project
sonar.projectName=Client-Project
sonar.projectVersion=2.0

sonar.sources=src
sonar.binaries=bin/classes
sonar.librairies=bin/dexedLibs,usr/local/android-sdk-linux

sonar.language=java
sonar.sourceEncoding=UTF-8

sonar.profile=Android Lint

How to set Sonar to find these android classes ?

Upvotes: 8

Views: 2583

Answers (3)

Jasper de Vries
Jasper de Vries

Reputation: 20178

In addition to Mikko's answer, I needed to set these properties in order to get FindBugs running properly as well:

sonar.libraries=libs/*.jar,/usr/local/android/android-sdk-linux/platforms/android-25/android.jar
sonar.java.binaries=bin/classes
sonar.java.libraries=libs/*.jar,/usr/local/android/android-sdk-linux/platforms/android-25/android.jar
sonar.java.test.libraries=libs/*.jar,/usr/local/android/android-sdk-linux/platforms/android-25/android.jar

Upvotes: 0

Mikel Pascual
Mikel Pascual

Reputation: 2211

Building up on Mikko's answer, note that you don't really have to manually keep the setting in sync with your targetSdk. You can get it from gradle as in:

def androidJarPath;
afterEvaluate {
    def rootDir = project.rootDir
    def localProperties = new File(rootDir, "local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        androidJarPath = sdkDir + "/platforms/" + android.compileSdkVersion + "/android.jar"
    }
}

sonarqube {
    properties {
        property "sonar.java.libraries", androidJarPath
        ...
    }
}

Cheers!

Upvotes: 2

Mikko Liikanen
Mikko Liikanen

Reputation: 675

To get rid of these errors, add android.jar location directly to sonar.libraries:

sonar.libraries=libs/*.jar,/usr/local/opt/android-sdk/platforms/android-18/android.jar

Two obvious drawbacks with this:

  1. Directly pointing to local environment. SonarQube project configuration doesn't support environment variables yet (https://jira.codehaus.org/browse/SONARUNNER-76).
  2. Directly pointing to a version of android platform; this is probably OK but needs to be manually kept in sync with your targetSdk

Upvotes: 3

Related Questions