Android 去除重复依赖库优化

01.如何查询重复库

  • 我相信你看到了这里会有疑问,网上有许多博客作了这方面说明。但是我在这里想说,如何查找自己项目的所有依赖关系树

    • 注意要点:其中app就是项目mudule名字。 正常情况下就是app!
    1
    gradlew app:dependencies
  • 关于依赖关系树的结构图如下所示,此处省略很多代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    |    |    |    |    |    |    \--- android.arch.core:common:1.1.1 (*)
    | | | | \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
    | +--- com.journeyapps:zxing-android-embedded:3.6.0
    | | +--- com.google.zxing:core:3.3.2
    | | \--- com.android.support:support-v4:25.3.1
    | | +--- com.android.support:support-compat:25.3.1 -> 28.0.0 (*)
    | | +--- com.android.support:support-media-compat:25.3.1
    | | | +--- com.android.support:support-annotations:25.3.1 -> 28.0.0
    | | | \--- com.android.support:support-compat:25.3.1 -> 28.0.0 (*)
    | | +--- com.android.support:support-core-utils:25.3.1 -> 28.0.0 (*)
    | | +--- com.android.support:support-core-ui:25.3.1 -> 28.0.0 (*)
    | | \--- com.android.support:support-fragment:25.3.1 -> 28.0.0 (*)
    \--- com.android.support:multidex:1.0.2 -> 1.0.3

02.如何代码去重配置

  • 然后查看哪些重复jar

    • image
  • 然后修改gradle配置代码

    1
    2
    3
    4
    api (rootProject.ext.dependencies["zxing"]){
    exclude module: 'support-v4'
    exclude module: 'appcompat-v7'
    }