我有一个名为library
的库模块,它具有两种风格的flavor1
和flavor2
。然后,我有两个应用程序模块,让它们分别称为app1
和app2
,它们将使用此库模块,每个模块将以特定的风格使用它。 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
,我不想在这里介绍。
答案 0 :(得分:1)
您应同时为missingDimensionStrategy
和app1
定义app2
。
例如:
// app1/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor1'
}
// app2/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor2'
}