Android app Module与library Module编译版本统一实现方法

需求背景:

在日常开发中,我们多用gradle进行项目构建,有一个app项目中有两个Module,其中A是application module,B是一个library module,同事A编译依赖B,且都有debug和release两个版本。请问:如果实现A和编译版本的统一,即编译A的debug版本也编译B的debug版本,编译A的release版本也编译B的release版本。
实现效果图如下:
编译A的debug版本也编译B的debug版本

编译A的release版本也编译B的release版本

实现方法:

1.将所有被依赖的library的build.gradle中添加

android {
     publishNonDefault true   //表示该Module不使用默认配置
}

在上图中application依赖了3个,则在3个module的build.gradle中均添加这句话。
2.在application module的build.gradle中,将其所有依赖的library都进行如下添加:

dependencies {

    releaseCompile project(path: ':library', configuration: 'release')
    debugCompile project(path: ':library', configuration: 'debug')
}

根据上图中的示例,则在application module中添加

dependencies {
    releaseCompile project(path: ':lib-zxing', configuration: 'release')
    debugCompile project(path: ':lib-zxing', configuration: 'debug')

    releaseCompile project(path: ':supertoasts', configuration: 'release')
    debugCompile project(path: ':supertoasts', configuration: 'debug')

    releaseCompile project(path: ':material-calendarview-library', configuration: 'release')
    debugCompile project(path: ':material-calendarview-library', configuration: 'debug')
}

3.重新build gradle即可实现上述需求。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值