我有两个模块,一个是应用程序,一个是库和两个外部maven库。
外部库略有差异,与maven分类器一起根据构建风格进行选择。
(子项目/模块)和(主模块)都根据风味使用相同的外部库。
我的问题是编译时无法控制/选择子项目库。
模块应用程序:
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
android {
productFlavors {
fOne {}
fTwo {}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:gridlayout-v7:22.2.1'
compile 'com.android.support:support-annotations:22.2.1'
// selecting the library based on the flavour
fOneCompile(group: 'com.xyz', name: 'SDK', version: '1.0', ext: 'aar')
fTwoCompile(group: 'com.xyz', name: 'SDK', version: '1.0', classifier: 'qa', ext: 'aar')
//<< the library also needs the com.xyz.SDK
fOneCompile project(path: ':library', configuration: "fOneCompile")
fTwoCompile project(path: ':library', configuration: "fTwoCompile")
}
模块库:
apply plugin: 'com.android.library'
android {
....
}
repositories{
jcenter()
flatDir{
dirs 'libs'
}
}
configurations {
fOne
fTwo
}
dependencies {
??? what goes here, flavours are not available ???
//the library also needs the com.xyz.SDK
fOneCompile(group: 'com.xyz', name: 'SDK', version: '1.0', ext: 'aar')
fTwoCompile(group: 'com.xyz', name: 'SDK', version: '1.0', classifier: 'qa', ext: 'aar')
}
模块库无法编译,因为它找不到SDK,我需要根据编译的风格包括一个。
发布于 2017-06-28 06:45:57
使用此配置:
defaultConfig {
publishNonDefault true
}
configurations {
fOneDebugCompile
fOneReleaseCompile
fTwoDebugCompile
fTwoReleaseCompile
}
发布于 2016-04-11 12:50:24
解决方案非常简单,因为存在重复的依赖关系,主项目选择适当的依赖项,在解决依赖关系时,可以在子模块中使用“提供”语句。
在这种情况下,可以将依赖项部分中的“编译”语句替换为模块库(子模块)中的“提供”语句:
模块库:
apply plugin: 'com.android.library'
android {
....
}
repositories{
jcenter()
flatDir{
dirs 'libs'
}
}
dependencies {
//the library also needs the com.xyz.SDK
provided(group: 'com.xyz', name: 'SDK', version: '1.0', ext: 'aar')
}
https://stackoverflow.com/questions/36156596
复制相似问题