在声呐分析中找不到Android类

我试图设置一个Android项目的声纳分析

分析是用sonarQube槽版本4.3完成的,android-plugin install,ANDROID_HOME envvariables设置在/ path / to / android / sdk上,用ant完成编译没有任何问题

执行运行良好,但我有大量的错误消息:

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 ... 

我的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 

如何设置声纳来find这些android类?

Solutions Collecting From Web of "在声呐分析中找不到Android类"

要摆脱这些错误,请直接将android.jar位置添加到sonar.libraries

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

这两个明显的缺点:

  1. 直接指向当地的环境。 SonarQube项目configuration不支持环境variables( https://jira.codehaus.org/browse/SONARUNNER-76 )。
  2. 直接指向android平台的一个版本; 这可能是好的,但需要手动保持与您的targetSdk同步

build立在Mikko的答案上,请注意,您并不需要手动将设置与targetSdk保持同步。 你可以从gradle中得到它,如下所示:

 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 ... } } 

干杯!

除了Mikko的回答,我还需要设置这些属性以使FindBugs正常运行:

 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