基于(主)项目模块风格的Gradle子项目外部库依赖项 [英] Gradle subproject external library dependency based on (main) project module flavours

查看:216
本文介绍了基于(主)项目模块风格的Gradle子项目外部库依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模块,分别是一个应用程序和一个
两个我使用的外部maven库。



外部库有轻微的差异,并根据构建风格与maven分类器一起选择。


$ b (子项目/模块)和(主模块)都使用基于风格的相同外部库。


我的问题是,当
编译时我无法控制/选择子项目库。

模块应用:

 应用插件:'android-sdk-manager'
apply插件:'com.android.application'

android {
productFlavors {
fOne {}
fTwo {}
}
}

依赖关系{
编译'com.android.support:appcompat-v7:22.2.1'
编译'com.android.support:gridlayout-v7:22.2.1'
compile'c​​om.android.support:support-annotations:22.2.1'

//根据风格选择库
fOneCompile(group:'com.xyz',名称:'SDK',版本:'1.0',ext:'aar')
fTwoCompile(组:'com.xyz',名称:'SDK',版本:'1.0',分类:'qa', ext:'aar')

//<<该库还需要com.xyz.SDK
fOneCompile项目(路径:':library',配置:fOneCompile)
fTwoCompile项目(路径:':library',配置:fTwoCompile)




$ b

模块库:

  apply plugin:'com.android.library'
android {
....


存储库{
jcenter()
flatDir {
dirs'libs'
}
}

配置{
fOne
fTwo
}

依赖关系{
???这里有什么,味道不可用?
//该库还需要com.xyz.SDK
fOneCompile(组:'com.xyz',名称:'SDK',版本:'1.0',ext:'aar')
fTwoCompile(group:'com.xyz',name:'SDK',version:'1.0',classifier:'qa',ext:'aar')
}
无法编译,因为它无法找到SDK,并且
需要包含一个基于

解决方案

使用此配置:

 defaultConfig {
publishNonDefault true
}

配置{
fOneDebugCompile
fOneReleaseCompile
fTwoDebugCompile
fTwoReleaseCompile
}


I have two modules an app and a library and two external maven libraries that I use.

The external libraries have slight differences and are selected based on the build flavour together with the maven classifier.

Both the (subproject/module) and the (main module) use the same external library based on the flavour.

My problem is I cannot control/select the subproject library when compiling.

Module App:

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")


}

Module library:

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')
}

Module library fails to compile because it can not find the SDK and I need to include one based on the flavour being compiled.

解决方案

Use this config:

defaultConfig {
       publishNonDefault true
}

configurations {
    fOneDebugCompile
    fOneReleaseCompile
    fTwoDebugCompile
    fTwoReleaseCompile
}

这篇关于基于(主)项目模块风格的Gradle子项目外部库依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆