androidgradlebuild-variant

Combine variant and build type in dependency implementation


I need to implement variant-specific libraries im my project, lets say i have:

flavorDimensions "dimensionOne", "dimensionTwo"

productFlavors {
    dimensionOneVariantOne {
        dimension "dimensionOne"
    }
    dimensionOneVariantTwo {
        dimension "dimensionOne"
    }
    dimensionTwoVariantOne {
        dimension "dimensionTwo"
    }
    dimensionTwoVariantTwo {
        dimension "dimensionTwo"
    }
}

and in dependency implementation, i need to use, for example

dimensionTwoVariantOneDebugImplementation("maven-library:version")
dimensionTwoVariantOneReleaseImplementation("maven-library:version")

I thought that was the correct syntax, but somewhy I'm not able to do that, I get a "Could not find method dimensionTwoVariantOneDebugImplementation() for arguments " error.

I defined two flavorDimensions because thats what I have in my real project, and the first one is not relevant for the implementation on that library. But I also tried including it with no success


Solution

  • @Edit

    Adding only one configuration wasn't enough, I had to add the full combinations in both configuration and dependency implementation, like

    configurations{
      dimensionOneVariantOneDimensionTwoVariantOneDebugImplementation
      dimensionOneVariantOneDimensionTwoVariantOneReleaseImplementation
      dimensionOneVariantTwoDimensionTwoVariantOneDebugImplementation
      dimensionOneVariantTwoDimensionTwoVariantOneReleaseImplementation
    }
    

    and the respective implementation blocks


    Apparently, all i needed was

    configurations{
        dimensionTwoVariantOneDebugImplementation
    }
    

    I'm not sure tho if not adding the other variants will have any impact