Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android classes not found during sonar anaysis

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 ?

like image 396
Laurent Cudini Avatar asked Jul 23 '14 10:07

Laurent Cudini


2 Answers

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
like image 55
Mikko Liikanen Avatar answered Nov 15 '22 00:11

Mikko Liikanen


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!

like image 31
Mikel Pascual Avatar answered Nov 15 '22 00:11

Mikel Pascual