Gradle dependencies for specific dimension and build type

Viewed 289

I have an app with multiple flavor dimensions:

  • version ( demo/free/paid/vip )
  • environment (test/acceptance/production)

And the usual build types: debug and release

this results in a whole list of build variants:

  • demoTestRelease
  • demoTestDebug
  • freeTestRelease
  • freeTestDebug
  • paidTestRelease
  • paidTestDebug
  • vipTestRelease
  • vipTestDebug
  • and so on for the other environments.

I can then set a specific dependency for a build variant like this.

android {
    configurations {
        vipTestReleaseImplementation
        // dozens of other configurations.
    }
    dependencies {
        vipTestReleaseImplementation fileTree('my_test_library')
        // dozens of dependencies.
    }
}

But this is not ideal because I would have to write down every single combination and literally end up with dozens of configurations.

Is there a way to define a dependency for a buildType together with a specific dimension? In my case the environment dimension? Like this:

android {
    configurations {
        // these configurations don't exist.
        testReleaseImplementation
        acceptanceReleaseImplementation
        productionReleaseImplementation
    }
    dependencies {
        debugImplementation fileTree('my_debug_library')

        // this would be nice but is not possible???
        testReleaseImplementation fileTree('my_test_library')
        acceptanceReleaseImplementation fileTree('my_test_library')
        productionReleaseImplementation fileTree('my_prod_library')
    }
}

I tried using a variantFilter but that just iterates over every build variant so I end up with duplicate dependencies. How do I solve this?

0 Answers
Related