Hello!
We are also running in to this issue, we are attempting to set up SonarCloud on our Gradlew Android multimodule application. In our case we are using SonarCloud’s integration with Azure Devops, and running a pipeline with the 3 tasks as recommended for that particular flavour of CI.
We’re still in the initial setup phases, so things like the gradle setup etc are still in flux bug the basics seem to be in place, it’s just this failure on the ContentProvider that seems to be messing things up. I’m very open to “there’s some other configuration of sonarqube/scanner/whatever that is missing from your gradle” but I’m finding no such description from online searches
Here’s our pipeline definition:
trigger:
- main
pool:
vmImage: macos-latest
steps:
- checkout: self
fetchDepth: 0
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'sonarqube-service-connect'
organization: '<OUR_ORGANIZATION>'
scannerMode: 'Other'
extraProperties: |
sonar.projectKey=<OUR_PROJECT_KEY>
sonar.projectName=<OUR_PROJECT_NAME>
- task: Gradle@2
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
sonarQubeRunAnalysis: true
sqGradlePluginVersionChoice: 'build'
tasks: 'clean jacocoTestReportBaseRelease'
# options: '--debug'
- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'
Out top level build.gradle.kts
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath("com.android.tools.build:gradle:8.1.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}")
// NOTE: Do not place your application dependencies here they belong
// in the individual module build.gradle files
classpath("org.jacoco:org.jacoco.core:0.8.10")
}
}
plugins {
id("com.google.dagger.hilt.android") version Versions.hilt apply false
id("com.android.dynamic-feature") version "8.1.1" apply false
id("org.jetbrains.kotlin.android") version Versions.kotlin apply false
id ("org.sonarqube") version "4.3.1.3277" apply false
}
tasks.register<Delete>("clean") {
delete(rootProject.buildDir)
}
We currently are only applying the sonar scanning to the main Android app, and none of the other modules. Here’s a somewhat redacted version of our app build.gradle.kts :
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
plugins {
id("de.mannodermaus.android-junit5") version "1.8.2.1"
kotlin("kapt")
id("com.google.dagger.hilt.android")
id("com.android.application")
kotlin("android")
kotlin("plugin.serialization")
id("jacoco")
id("io.sentry.android.gradle") version "3.12.0"
id ("org.sonarqube")
}
jacoco {
toolVersion = "0.8.10"
}
android {
compileSdk = 33
defaultConfig {
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
applicationId = <APPLICATION_ID>
minSdk = 29
targetSdk = 33
versionCode = 200
versionName = "1.0.0"
testInstrumentationRunner = "<CUSTOM_RUNNER_PACKAGE>.HiltTestRunner"
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
javaCompileOptions {
annotationProcessorOptions {
compilerArgumentProviders(
RoomSchemaArgProvider(File(projectDir, "schemas"))
)
}
}
buildFeatures {
viewBinding = true
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = Versions.compose
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
testOptions {
unitTests.isReturnDefaultValues = true
unitTests.all {
it.jvmArgs(
"--add-opens=java.base/java.time=ALL-UNNAMED"
)
}
}
lint {
abortOnError = false
showAll = true
}
namespace = "<OUR_NAMESPACE>"
dynamicFeatures += "<SOME_DYNAMIC_FEATURES>"
sourceSets {
// Adds exported schema location as test app assets.
getByName("androidTest").assets.srcDir("$projectDir/schemas")
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.core:core-ktx:1.10.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.1")
implementation("commons-codec:commons-codec:1.15")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
implementation("com.google.guava:guava:31.1-android")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.4.0")
implementation("com.squareup.retrofit2:converter-scalars:2.4.0")
implementation("com.squareup.retrofit2:converter-jackson:2.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.10.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc")
implementation("com.google.dagger:hilt-android:${Versions.hilt}")
implementation("androidx.test.ext:truth:1.5.0")
// implementation( "com.google.android.play:feature-delivery-ktx:+")
implementation("com.google.android.play:core:1.3.4")
testImplementation("org.junit.jupiter:junit-jupiter")
kapt("com.google.dagger:hilt-compiler:${Versions.hilt}")
implementation("androidx.room:room-runtime:${Versions.room}")
kapt("androidx.room:room-compiler:${Versions.room}")
implementation("androidx.room:room-ktx:${Versions.room}")
androidTestImplementation("androidx.room:room-testing:${Versions.room}")
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycle}")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:${Versions.lifecycle}")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:${Versions.lifecycle}")
implementation("androidx.lifecycle:lifecycle-service:${Versions.lifecycle}")
// JVM dependency
implementation("org.slf4j:slf4j-api:${Versions.slf4j}")
implementation("com.github.tony19:logback-android:${Versions.logback}")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("com.google.android.material:material:1.8.0")
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
implementation("androidx.test.ext:junit-ktx:1.1.5")
implementation("com.google.zxing:core:3.5.1")
implementation("androidx.test:rules:1.5.0")
testImplementation("junit:junit:4.13.2")
// Compose
implementation("androidx.compose.ui:ui:${Versions.compose}")
implementation("androidx.compose.ui:ui-tooling:${Versions.compose}")
implementation("androidx.compose.foundation:foundation:${Versions.compose}")
implementation("androidx.compose.material:material-icons-core:${Versions.compose}")
implementation("androidx.compose.material:material-icons-extended:${Versions.compose}")
implementation("androidx.compose.runtime:runtime-livedata:${Versions.compose}")
implementation("androidx.compose.material3:material3:${Versions.material3}")
implementation("androidx.compose.material3:material3-window-size-class:${Versions.material3}")
implementation("androidx.activity:activity-ktx:${Versions.compose}")
implementation("androidx.activity:activity-compose:${Versions.compose}")
implementation("androidx.navigation:navigation-compose:${Versions.nav}")
implementation("com.google.accompanist:accompanist-flowlayout:0.30.0")
implementation("com.google.accompanist:accompanist-webview:0.30.0")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:${Versions.compose}")
debugImplementation("androidx.compose.ui:ui-test-manifest:${Versions.compose}")
//WorkManager
implementation("androidx.work:work-runtime-ktx:${Versions.work}")
androidTestImplementation("androidx.work:work-testing:${Versions.work}")
implementation("androidx.hilt:hilt-common:1.0.0")
implementation("androidx.hilt:hilt-work:1.0.0")
kapt("androidx.hilt:hilt-compiler:1.0.0")
implementation("androidx.hilt:hilt-navigation-compose:1.0.0")
testImplementation("ch.qos.logback:logback-classic:1.2.11")
testImplementation("org.junit.jupiter:junit-jupiter:${Versions.junit5}")
testImplementation("io.mockk:mockk-android:${Versions.mockk}")
testImplementation("io.mockk:mockk-agent:${Versions.mockk}")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
testImplementation("com.squareup.okhttp3:mockwebserver:4.10.0")
androidTestCompileOnly("androidx.test:rules:1.5.0")
androidTestImplementation("org.junit.jupiter:junit-jupiter-api:${Versions.junit5}")
androidTestImplementation("de.mannodermaus.junit5:android-test-core:1.3.0")
androidTestImplementation("androidx.test:runner:1.5.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.5.1")
androidTestImplementation("com.google.dagger:hilt-android-testing:${Versions.hilt}")
androidTestImplementation("androidx.arch.core:core-testing:2.1.0")
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
androidTestRuntimeOnly("de.mannodermaus.junit5:android-test-runner:1.3.0")
kaptAndroidTest("com.google.dagger:hilt-android-compiler:${Versions.hilt}")
}
configurations.testImplementation {
exclude("logback-android")
}
kapt {
correctErrorTypes = true
}