从产品构建中排除特定的子模块
Exclude specific sub-modules from product build
好的,所以我有不同的产品口味和不同的子模块。实现子模块的权利,我这样做:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':A-Android')
implementation project(path: ':B-Android')
implementation project(path: ':C-Android')
}
是否可以仅针对特定产品风味实施子模块 :A-Android
?怎么样?
是的,只能为特定风格配置依赖项。这里是 Declare dependencies 文档的摘录:
Declare dependencies
You can configure a dependency for a specific build variant or
testing source set by prefixing the name of the build variant or
testing source set before the Implementation keyword, as shown in the
following example.
dependencies {
// Adds the local "mylibrary" module as a dependency to the "free" flavor.
freeImplementation project(":mylibrary")
// Adds a remote binary dependency only for local tests.
testImplementation 'junit:junit:4.12'
// Adds a remote binary dependency only for the instrumented test APK.
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
For more information, see Add build dependencies.
因此,如果您有 production
和 development
两种口味,那么您可以像这样添加依赖项:
dependencies {
productionImplementation project(path: ':A-Android')
DevelopmentImplementation project(path: ':B-Android')
..
}
好的,所以我有不同的产品口味和不同的子模块。实现子模块的权利,我这样做:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':A-Android')
implementation project(path: ':B-Android')
implementation project(path: ':C-Android')
}
是否可以仅针对特定产品风味实施子模块 :A-Android
?怎么样?
是的,只能为特定风格配置依赖项。这里是 Declare dependencies 文档的摘录:
Declare dependencies
You can configure a dependency for a specific build variant or testing source set by prefixing the name of the build variant or testing source set before the Implementation keyword, as shown in the following example.
dependencies { // Adds the local "mylibrary" module as a dependency to the "free" flavor. freeImplementation project(":mylibrary") // Adds a remote binary dependency only for local tests. testImplementation 'junit:junit:4.12' // Adds a remote binary dependency only for the instrumented test APK. androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }
For more information, see Add build dependencies.
因此,如果您有 production
和 development
两种口味,那么您可以像这样添加依赖项:
dependencies {
productionImplementation project(path: ':A-Android')
DevelopmentImplementation project(path: ':B-Android')
..
}