Gradle 排除排除本地项目 部分依赖

1. 查看依赖树

./gradlew app:dependencies --configuration releaseRuntimeClasspath
+--- com.android.support.constraint:constraint-layout:1.1.2
|    \--- com.android.support.constraint:constraint-layout-solver:1.1.2
+--- com.android.support:appcompat-v7:26.1.0
|    +--- com.android.support:support-annotations:26.1.0 -> 27.1.1
|    +--- com.android.support:support-v4:26.1.0
|    |    +--- com.android.support:support-compat:26.1.0 -> 27.1.1
|    |    |    +--- com.android.support:support-annotations:27.1.1
|    |    |    \--- android.arch.lifecycle:runtime:1.1.0
|    |    |         +--- android.arch.lifecycle:common:1.1.0
|    |    |         \--- android.arch.core:common:1.1.0
|    |    +--- com.android.support:support-media-compat:26.1.0
|    |    |    +--- com.android.support:support-annotations:26.1.0 -> 27.1.1
|    |    |    \--- com.android.support:support-compat:26.1.0 -> 27.1.1 (*)
|    |    +--- com.android.support:support-core-utils:26.1.0 -> 27.1.1
|    |    |    +--- com.android.support:support-annotations:27.1.1
|    |    |    \--- com.android.support:support-compat:27.1.1 (*)
|    |    +--- com.android.support:support-core-ui:26.1.0 -> 27.1.1
|    |    |    +--- com.android.support:support-annotations:27.1.1
|    |    |    +--- com.android.support:support-compat:27.1.1 (*)
|    |    |    \--- com.android.support:support-core-utils:27.1.1 (*)
|    |    \--- com.android.support:support-fragment:26.1.0 -> 27.1.1
|    |         +--- com.android.support:support-compat:27.1.1 (*)
|    |         +--- com.android.support:support-core-ui:27.1.1 (*)
|    |         +--- com.android.support:support-core-utils:27.1.1 (*)
|    |         +--- com.android.support:support-annotations:27.1.1
|    |         +--- android.arch.lifecycle:livedata-core:1.1.0
|    |         |    +--- android.arch.lifecycle:common:1.1.0
|    |         |    +--- android.arch.core:common:1.1.0
|    |         |    \--- android.arch.core:runtime:1.1.0
|    |         |         \--- android.arch.core:common:1.1.0
|    |         \--- android.arch.lifecycle:viewmodel:1.1.0
|    +--- com.android.support:support-vector-drawable:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0 -> 27.1.1
|    |    \--- com.android.support:support-compat:26.1.0 -> 27.1.1 (*)
|    \--- com.android.support:animated-vector-drawable:26.1.0
|         +--- com.android.support:support-vector-drawable:26.1.0 (*)
|         \--- com.android.support:support-core-ui:26.1.0 -> 27.1.1 (*)
+--- com.android.support:recyclerview-v7:26.1.0
|    +--- com.android.support:support-annotations:26.1.0 -> 27.1.1
|    +--- com.android.support:support-compat:26.1.0 -> 27.1.1 (*)
|    \--- com.android.support:support-core-ui:26.1.0 -> 27.1.1 (*)
\--- com.github.bumptech.glide:glide:4.7.1
     +--- com.github.bumptech.glide:gifdecoder:4.7.1
     |    \--- com.android.support:support-annotations:27.1.1
     +--- com.github.bumptech.glide:disklrucache:4.7.1
     +--- com.github.bumptech.glide:annotations:4.7.1
     \--- com.android.support:support-fragment:27.1.1 (*)

符号的含义:
x.x.x () 该依赖已经有了,将不再重复依赖。
x.x.x -> x.x.x 该依赖的版本被箭头所指的版本代替。
x.x.x -> x.x.x(
) 该依赖的版本被箭头所指的版本代替,并且该依赖已经有了,不再重复依赖。

2. Exclude 排除

排除所有:
// 在build.gradle 中添加下面节点
configurations {
    all*.exclude module: "support-fragment"
}
排除指定:
  • 非本地项目
implementation ('com.github.bumptech.glide:glide:4.7.1'){
        exclude module:"support-fragment"
}
  • 本地项目
compile(project(':xxx')) {
    exclude group: 'com.facebook.react', module: 'react-native'
}

3. Force 强制指定

强制所有:
configurations.all {
   resolutionStrategy {
       force 'com.android.support:support-fragment:26.1.0'
   }
}
强制指定:
// 在build.gradle 中添加下面节点
implementation ( 'com.meituan.android.pay.quickpass.baseinterface:library:1.0.0') {
        force = true
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 项目依赖module时可能会有相同的依赖,就会报以下错误: gradle 排除部分依赖:以前都是以为只有 用坐标依...
    goolong阅读 11,183评论 1 5
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,052评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,112评论 25 709
  • 春天里 王华 我已经坐在了春天里。可我必...
    王华_3533阅读 2,732评论 1 3