我试图在Android项目上设置声纳分析
分析是使用sonarQube通过sonar-runner的版本4.3,android-plugin安装,ANDROID_HOME env变量设置在/ 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
...
我的声纳-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
如何设置Sonar来找到这些android类?
答案 0 :(得分:3)
要摆脱这些错误,请将android.jar位置直接添加到sonar.libraries
:
sonar.libraries=libs/*.jar,/usr/local/opt/android-sdk/platforms/android-18/android.jar
这有两个明显的缺点:
答案 1 :(得分:2)
根据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
...
}
}
干杯!
答案 2 :(得分:0)
除了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