Android Studio 中 处理 Gradle 依赖的几种方法的介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wa172126691/article/details/82465990

exclude

exclude : 剔除依赖中的某个模块
例:

// 根据组织名 + 构建名剔除

//recyclerview 不想要依赖 com.android.support:support-annotations:26.1.0,就可以这么做
implementation ('com.android.support:recyclerview-v7:26.1.0'){
        exclude group: 'com.android.support', module: 'support-annotations'  
    }

//剔除 retrofit2 中的 okhttp3 模块    
implementation('com.squareup.retrofit2:retrofit:2.3.0') {
        exclude group: 'com.squareup.okhttp3'
    }    

force

force : 强制指定依赖版本
**例,我想要所有 com.android.support:appcompat-v7:26.1.0 的依赖版本为 27.1.1 怎么办呢
在只需要在 build.gradle 中加上 force true 即可**

implementation("com.android.support:appcompat-v7:27.1.1"){
        force true
    }

transitive

transitive : 依赖传递特性,使用的时候,通常设置为 false 。即关闭依赖传递
例如项目中不希望 recyclerview 使用它所依赖的库 :

implementation ('com.android.support:recyclerview-v7:27.1.1'){
        transitive  false
 }

猜你喜欢

转载自blog.csdn.net/wa172126691/article/details/82465990