Can't run for a specific flavor by using androidVariant

  • versions: sonarscanner-for-gradle version 3.3 (also tried 3.1.1 and 3.0), Gradle 6.9, Android plugin 4.2.2
  • error: Unable to find variant '...' to use for SonarQube analysis. Candidates are: ...
1: Unable to find variant 'aaaaa' to use for SonarQube analysis. Candidates are: productionDebug, developmentDebug, productionRelease, developmentRelease
2: Unable to find variant 'developmentDebug' to use for SonarQube analysis. Candidates are: debug, release
3: Unable to find variant 'debug' to use for SonarQube analysis. Candidates are: productionDebug, developmentDebug, productionRelease, developmentRelease
4: Unable to find variant 'development' to use for SonarQube analysis. Candidates are: productionDebug, developmentDebug, productionRelease, developmentRelease
  • steps to reproduce:
    Run ./gradlew sonarqube on an Android project with multiple flavors, while using the following config:
// root build.gradle
subprojects {
    apply plugin: 'org.sonarqube' // this does not seem to make any difference
    sonarqube() {
        androidVariant "aaaaa"
    }
    properties {
        // ...
    }
}

project(":react-native-firebase_app") {
    sonarqube {
        skipProject = true
    }
}

sonarqube() {
    properties {
        property "sonar.host.url", "https://sonarcloud.io"
        property "sonar.organization", "a"
        property "sonar.projectKey", "b"
    }
}
  • potential workaround: don’t specify androidVariant and let the task waste time on duplicate variants you don’t need to check

P.S. Not sure if relevant, but we configure the source folders of all flavors additionally like:

        production.res.srcDirs = ['src/production/res']
        production.java.srcDirs = ['src/common/java']
  • We also use underscores in the names of flavors (I cleaned them up here to make it more readable):
  • We use _production and _development (so also _productionDebug and _developmentDebug etc).
  • If I omit androidVariant, I get these log messages:
Selected primary task 'sonarqube' from project :
No variant name specified to be used by SonarQube. Default to 'productionDebug'
No variant name specified to be used by SonarQube. Default to 'debug'

Hello @nokite,

Thanks for your message. Could you please share the configuration of your variants. It looks like your variants are not found by our scanner.

Regards,
Margarita

Hello Margarita,

I am also getting the same error when i ran ./gradlew sonarqube --info

Task :app:sonarqube FAILED
No variant name specified to be used by SonarQube. Default to ‘debug’
file or directory ‘/Users/bansoash/Desktop/poc-presonnal/kotlin-android-sample-projects-with-source-code-in-android-studio/How to convert website into kotlin android app in android studio/app/libs’, not found
file or directory ‘/Users/bansoash/Desktop/poc-presonnal/kotlin-android-sample-projects-with-source-code-in-android-studio/How to convert website into kotlin android app in android studio/app/libs’, not found
file or directory ‘/Users/bansoash/Desktop/poc-presonnal/kotlin-android-sample-projects-with-source-code-in-android-studio/How to convert website into kotlin android app in android studio/app/libs’, not found
file or directory ‘/Users/bansoash/Desktop/poc-presonnal/kotlin-android-sample-projects-with-source-code-in-android-studio/How to convert website into kotlin android app in android studio/app/libs’, not found
file or directory ‘/Users/bansoash/Desktop/poc-presonnal/kotlin-android-sample-projects-with-source-code-in-android-studio/How to convert website into kotlin android app in android studio/app/libs’, not found

Project level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = ‘1.3.40’
repositories {
google()
jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:7.2.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
repositories {
google()
jcenter()

}

}

task clean(type: Delete) {
delete rootProject.buildDir
}

=======================

Module level build.gradle

plugins {
id ‘com.android.application’
id ‘kotlin-android’
id ‘kotlin-kapt’
id “org.sonarqube” version “3.4.0.2513”
id ‘kotlin-android-extensions’

}
sonarqube {
properties {
property “sonar.projectName”, “pe-kotlin-cc”
property “sonar.projectKey”, “com.adidas.pesh:pe-kotlin-cc”
property “sonar.sources”, “src”
property “sonar.language”, “kotlin”
property “sonar.sourceEncoding”, “UTF-8”
property “sonar.test.inclusions”, [“src/test/java”]
property “sonar.binaries” ,“build/classes/kotlin”
property “sonar.java.binaries” ,“build/classes/, build/classes/kotlin”
property “sonar.binaries”, “build/intermediates/classes/, app/build/classes/”

}

}
android {
compileSdkVersion 30
defaultConfig {
applicationId “com.visitbazar”
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName “1.0”
testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’
}
}
}

dependencies {
implementation fileTree(dir: ‘libs’, include: [‘*.jar’])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//noinspection GradleCompatible
implementation “com.android.support:appcompat-v7:27.1.1”
implementation ‘com.android.support.constraint:constraint-layout:1.1.3’
testImplementation ‘junit:junit:4.12’
androidTestImplementation ‘com.android.support.test:runner:1.0.2’
androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.2’
}