首页 > 解决方案 > 特定维度和构建类型的 Gradle 依赖项

问题描述

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

和通常的构建类型:debugrelease

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

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

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

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

有没有办法为 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')
    }
}

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

标签: androidgradleconfigurationdependenciesandroid-build-flavors

解决方案


推荐阅读