使用 gradle 模块作为具有特定风格的依赖项
Use gradle module as a dependency with specific flavor
我有一个名为 library
的库模块,它有两种风格 flavor1
和 flavor2
。然后我有两个应用程序模块,我们称它们为 app1
和 app2
,它们将使用这个库模块,每个模块都将以特定的风格使用它。例如。 app1
将始终使用 library
和 flavor1
风格。我应该如何配置 gradle 依赖项以使其执行我想要的操作?如果我只在 app1
build.gradle
中尝试 implementation project(':library')
它显然不起作用,因为它不知道选择哪种口味..所以我尝试了 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
我在 SO 上看到了一些问题,比如 here 说要将风格从库模块复制到主应用程序模块,但这对我来说没有意义,app1
没有对flavor2
一无所知,我不想在那里介绍它。
您应该为 app1
和 app2
定义 missingDimensionStrategy
。
例如:
// app1/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor1'
}
// app2/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor2'
}
我有一个名为 library
的库模块,它有两种风格 flavor1
和 flavor2
。然后我有两个应用程序模块,我们称它们为 app1
和 app2
,它们将使用这个库模块,每个模块都将以特定的风格使用它。例如。 app1
将始终使用 library
和 flavor1
风格。我应该如何配置 gradle 依赖项以使其执行我想要的操作?如果我只在 app1
build.gradle
中尝试 implementation project(':library')
它显然不起作用,因为它不知道选择哪种口味..所以我尝试了 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
我在 SO 上看到了一些问题,比如 here 说要将风格从库模块复制到主应用程序模块,但这对我来说没有意义,app1
没有对flavor2
一无所知,我不想在那里介绍它。
您应该为 app1
和 app2
定义 missingDimensionStrategy
。
例如:
// app1/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor1'
}
// app2/build.gradle
defaultConfig {
missingDimensionStrategy 'library', 'flavor2'
}