使用gradle模块作为具有特定风格的依赖项

时间:2019-05-27 10:28:09

标签: android gradle module android-gradle

我有一个名为library的库模块,它具有两种风格的flavor1flavor2。然后,我有两个应用程序模块,让它们分别称为app1app2,它们将使用此库模块,每个模块将以特定的风格使用它。 app1将始终使用具有library风格的flavor1。我应该如何配置gradle依赖项以使其按照我的意愿进行?如果我仅在implementation project(':library') app1中尝试build.gradle,则显然不起作用,因为它不知道选择哪种口味。.因此,我尝试了类似implementation project(path: ':library', configuration: 'flavor1Release')的方法,但也不行,它会打印很多错误,例如

ERROR: Unable to resolve dependency for ':app1@debug/compileClasspath': Could not resolve project :library.
Show Details
Affected Modules: app1

ERROR: Unable to resolve dependency for ':app1@debugAndroidTest/compileClasspath': Could not resolve project :library.
Show Details
Affected Modules: app1

ERROR: Unable to resolve dependency for ':app1@debugUnitTest/compileClasspath': Could not resolve project :library.
Show Details
Affected Modules: app1

ERROR: Unable to resolve dependency for ':app1@release/compileClasspath': Could not resolve project :library.
Show Details
Affected Modules: app1

ERROR: Unable to resolve dependency for ':app1@releaseUnitTest/compileClasspath': Could not resolve project :library.
Show Details
Affected Modules: app1

我在here 这样的地方看到了一些问题,说要从库模块复制风味到主应用程序模块,但对我来说没有任何意义,app1一无所知关于flavor2,我不想在这里介绍。

1 个答案:

答案 0 :(得分:1)

您应同时为missingDimensionStrategyapp1定义app2

例如:

// app1/build.gradle

 defaultConfig {
    missingDimensionStrategy 'library', 'flavor1'
}

// app2/build.gradle

 defaultConfig {
    missingDimensionStrategy 'library', 'flavor2'
}