[英]Use gradle module as a dependency with specific flavor
我有一个名为library
的库模块,该库模块具有两个flavor1
和flavor2
。 然后,我有两个应用程序模块,让我们将其命名为app1
和app2
,它们将使用此库模块,每个模块将以特定的风格使用它。 app1
将始终使用带有flavor1
风味的library
。 我应该如何配置gradle依赖项以使其按照我的意愿进行? 如果我仅在app1
build.gradle
尝试implementation project(':library')
, 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
我在这里看到了一些问题上如此喜欢这里 ,说从库模块到主应用程序模块复制的口味,但它没有任何意义,我, app1
并不知道任何有关flavor2
,我不希望它介绍那里。
您应该为app1
和app2
定义missingDimensionStrategy
。
例如:
// app1/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor1'
}
// app2/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor2'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.