Substituting dependency with different name

I am trying to substitute a dependency with another that provides the same interface, but is not named the same. However, I am running into a problem where it seems that Gradle is assuming that the name of the file stays the same.

I have Android ARchives (AARs) available on coordinates like “com.example:design-brandX” and “com.example:design-brandY”. These two different AARs expose the same interface, but provide different colors, etc. for use within my Android app.

I am trying to create a “design” module in my codebase that will include the AAR, add some functionality on top of it. Then my “app” module will depend on “design” and, ideally, swap out the branded colors at build time with the appropriate one for the version of the app that is being built.

I’ve tried this:

configurations.all { config ->
    android.applicationVariants.all { variant ->
        def flavor = variant.productFlavors.get(0).name
        if ( {
            resolutionStrategy.dependencySubstitution {
                substitute module('com.example:design-brandX') with project("com.example:$flavor:$design_version")

However, when I try to run this, I get an error like so:

> Could not find design-brandX.aar (com.example:design-brandY:1.0.3).
  Searched in the following locations:

As you can see, it is trying to find the brandX AAR file under the brandY directory structure. Is there a way to get it to look for the new, correct brandY AAR file? Or another approach to this problem?

I think I may have found a solution by approaching the problem in a slightly different direction. Instead of substituting the dependency, it seems I can exclude the transitive dependency in my consuming project, and just provide the version of the dependency that I want there.

dependencies {
    implementation(project(':design')) {
        exclude group: 'com.example', module: 'design-brandX'
    brandXImplementation 'com.example:design-brandX:1.0.3'
    brandYImplementation 'com.example:design-brandY:1.0.3'