Android 基于(主)项目模块风格的Gradle子项目外部库依赖关系
我有两个模块,一个应用程序和一个库 我使用的两个外部maven库 外部库略有不同,根据构建风格和maven分类器选择 (子项目/模块)和(主模块)基于味道使用相同的外部库 我的问题是我无法控制/选择子项目库 编译 模块应用程序:Android 基于(主)项目模块风格的Gradle子项目外部库依赖关系,android,gradle,Android,Gradle,我有两个模块,一个应用程序和一个库 我使用的两个外部maven库 外部库略有不同,根据构建风格和maven分类器选择 (子项目/模块)和(主模块)基于味道使用相同的外部库 我的问题是我无法控制/选择子项目库 编译 模块应用程序: apply plugin: 'android-sdk-manager' apply plugin: 'com.android.application' android { productFlavors { fOne {} fTwo {} } } dependenci
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')
}
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')
}
模块库无法编译,因为它找不到SDK和I
需要根据编译的味道包含一个。解决方案非常简单,因为存在重复的依赖项和 主项目选择适当的依赖项,可以使用“提供的” 解决依赖关系时子模块中的语句 在这种情况下,可以替换依赖项中的“compile”语句 模块库(子模块)中带有“提供”的部分: 模块库:
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')
}
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')
}
使用此配置:
defaultConfig {
publishNonDefault true
}
configurations {
fOneDebugCompile
fOneReleaseCompile
fTwoDebugCompile
fTwoReleaseCompile
}
“应用插件:'com.android.library'”将其添加到Bmy bad中,该插件未被复制,也不是问题所在。我已经更新了这个问题。主项目的“设置gradle”在项目A的cli上有“include';projectB'”。/gradlew--info--stacktrace:projectB:clean:projectB:assembleDebug”用于父项目,用于库