Gradle笔记(android)

  1. 看依赖树
gradlew :app:dependencies
  1. 依赖传递:默认依赖传递是true,transitive= true。比如A依赖了B,B依赖了C,C依赖了D。则A会依赖BCD
配置全局的依赖不传递
configurations.all {
   transitive = false
}

配置单个依赖的依赖不传递
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
       transitive = false
   }
  1. 同种依赖方式的依赖,多个版本,相同的库会以最高版本为准
compile "com.tencent.module:1.0"
compile "com.tencent.module:2.0"
因为同样是以compile的方式依赖,所以会以最高的com.tencent.module:2.0为准
  1. 不同依赖方式的依赖,多个版本会有冲突,解决方案
1. force强制指定版本
    全局指定某个库的版本
    configurations.all {
       resolutionStrategy {
           force 'org.hamcrest:hamcrest-core:1.3'
       }
    }
    
    单独指定
    compile("com.tencent.module:1.0"){
        force "com.tencent.module:1.0"
    }
2. exclude排除某个版本的库不加入编译
    全局排除某个库的版本
    configurations {
       all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
    }
    也可以只指定group
    configurations {
       all*.exclude group: 'com.android.support.test'
    }
    
    指定排除某个依赖的版本库
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
       exclude group: 'org.hamcrest'
   }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值