androidgradleandroid-productflavors

Android: Configuration with name not found - Multiple flavors implementation


I'm trying to implement dependencies only for a specific build variant.

I have 4 flavors split in 2 dimensions as follows:

flavorDimensions += listOf(
    ProjectAndroidConstants.APP_TYPE_DIMENSION,
    ProjectAndroidConstants.OPERATING_SYSTEM_DIMENSION
)


productFlavors {
    // 'operatingSystem' dimension
    create(ProjectAndroidConstants.ANDROID_FLAVOR) {
        isDefault = true
        dimension = ProjectAndroidConstants.OPERATING_SYSTEM_DIMENSION
    }

    create(ProjectAndroidConstants.HUAWEI_FLAVOR) {
        dimension = ProjectAndroidConstants.OPERATING_SYSTEM_DIMENSION
    }

    // 'appType' dimension
    create(ProjectAndroidConstants.TOTO_FLAVOR) {
        isDefault = true
        dimension = ProjectAndroidConstants.APP_TYPE_DIMENSION
    }

    create(ProjectAndroidConstants.TATA_FLAVOR) {
        dimension = ProjectAndroidConstants.APP_TYPE_DIMENSION
    }
}

The problem is a single flavor implementation works but not a combinaison:

// This works
"${ProjectAndroidConstants.TOTO_FLAVOR}Implementation("com.myproject.android:authentication-session:0.1.0")


// This doesn't work and I get error: Configuration with name 'totoAndroidImplementation' not found
    "${ProjectAndroidConstants.TOTO_FLAVOR}${ProjectAndroidConstants.ANDROID_FLAVOR}Implementation"("com.myproject.android:authentication-session:0.1.0")

On this page there is an example of Implementation but with only one dimension and when there is multiple dimensions there is no Implementation example.

I precise that work with Kotlin DSL

EDIT: I have took care of the camel case in my constant already. But since I already got 2 answers focusing on my concatenation instead of the real problem, I'm making clear that here is one of my variant: variant

So we can see totoAndroid variant

And this hardcoded string instead of using my concatenation:

"totoAndroidImplementation("com.swissquote.android:authentication-session:0.1.0")

Does not work We can effectively see that the configuration totoAndroid same as variant, is not found.

error message


Solution

  • According to the documentation, this is supposed to work with two dimensions.

    Combine multiple product flavors with flavor dimensions


    The second part of this string likely just isn't properly capitalized.
    Concatenating ${...}${...} defintely won't result in camel-case.

    ${ProjectAndroidConstants.TOTO_FLAVOR}${ProjectAndroidConstants.ANDROID_FLAVOR}Implementation

    These important seeming ProjectAndroidConstants make everything unreadable.
    And not sure if this would result in totoAndroidImplementation (not found) or maybe androidTotoImplementation? This should be by the order of flavorDimensions.

    Assuming the string may be correct, it might still may require the corresponding sourceSets. productFlavors generate the variants, but one needs sourceSets to declare dependencies.

    sourceSets {
        create("totoAndroid") {
            java.srcDirs("src/main/kotlin", "src/totoAndroid/kotlin")
        }
    }
    

    Then it should be able to add the dependency:

    totoAndroidImplementation("com.myproject.android:authentication-session:0.1.0")
    

    Which is not the same as the likely incorrectly concatenated: totoandroidImplementation.