特定维度和构建类型的 Gradle 依赖关系

Wir*_*ing 6 configuration dependencies android gradle android-build-flavors

我有一个具有多种风味维度的应用程序:

  • 版本(演示/免费/付费/vip)
  • 环境(测试/验收/生产)

以及常见的构建类型:debug和release

这会产生构建变体的完整列表:

  • 演示测试版
  • 演示测试调试
  • 免费测试发布
  • 自由测试调试
  • 付费测试版
  • 付费测试调试
  • vip测试发布
  • vip测试调试
  • 其他环境依此类推。

然后我可以为这样的构建变体设置特定的依赖关系。

android {
    configurations {
        vipTestReleaseImplementation
        // dozens of other configurations.
    }
    dependencies {
        vipTestReleaseImplementation fileTree('my_test_library')
        // dozens of dependencies.
    }
}
Run Code Online (Sandbox Code Playgroud)

但这并不理想,因为我必须写下每一个组合,最终会得到数十种配置。

有没有办法定义 buildType 与特定维度的依赖关系?就我而言,环境维度?像这样:

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')
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用 avariantFilter但它只是迭代每个构建变体,所以我最终得到了重复的依赖项。我该如何解决这个问题?