摇篮 - 依赖关系库复制 [英] gradle - library duplicates in dependencies

查看:165
本文介绍了摇篮 - 依赖关系库复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有摇篮的Andr​​oid项目。问题是: 在项目查看我看到支持-V4的几个版本的库,例如支持-V4 -21.0.3 支持-v4-22.2.0

但是 build.gradle 我没有支持-V4 的。

不过,我在 build.gradle 〜10等的依赖关系。例如 appcompat-V7:22.2.0 。我可以表明, appcompat-V7:22.2.0 实际上还要考虑支持-v4-22.2.0 的Maven依赖和隐式拉它。但我没有想法谁拉支持-v4-21.0.3

据我知道这一切的库将在我的APK包装和增加体重APK的。

所以,我有下一个问题:

  1. 如何避免重复库?
  2. 如何看到Android的工作室Maven的依赖?
  3. 如何检测哪些库需要这个库?比如哪个库需要支持-v4-21.0.3 在我的项目?
解决方案

查找重复的依赖或所需的依赖,你可以想像在树库的依赖。执行摇篮命令如下。

 摇篮-q依赖yourProject:依赖--configuration编译
 

需要注意的是,在Windows中运行 gradlew 如下。

  gradlew -q依赖yourProject:依赖--configuration编译
 

该命令的结果会告诉你所有的依赖人类可读的树层次结构如下图所示。

 编译 - 类路径编制的主要来源。
+ --- org.androidannotations:androidannotations-API:3.2
+ --- com.android.support:support-annotations:22.1.1
+ --- com.squareup:奥托:1.3.6
+ --- in.srain.cube:网格视图与 - 页眉页脚:1.0.10
+ --- com.nostra13.universalimageloader:通用图像装载机:1.9.3
+ --- com.github.chrisbanes.photoview:库:1.2.3
+ --- org.simpleframework:简单的xml:2.7.1
+ --- com.google.android.gms:玩-服务基地:6.5 +  - >。 87年6月5日
+ ---项目:yo​​urProject
| + --- com.loopj.android:android-async-http:1.4.6
| + --- org.apache.httpcomponents:httpmime:4.2.5
| | \ --- org.apache.httpcomponents:的HttpCore:4.2.4
| \ --- com.google code.gson:GSON:2.3.1
+ ---项目:Facebook的
| \ --- com.android.support:appcompat-v7:22.1.1
| \ --- com.android.support:support-v4:22.1.1
| \ --- com.android.support:support-annotations:22.1.1  - > 22.2.0
 

您可以看到被覆盖的依赖关系,并决定考虑哪些应该避免的。在上面的例子中,最后一行 com.android.support:support-annotations presents从 22.1.1 重写以 22.2.0 内部。

为了避免重复,您可以添加排除每个项目的条款 build.gradle 文件。

 编译('com.github.chrisbanes.photoview:图书馆:1.2.3'){
    排除组:com.android.support
}
编译(org.simpleframework:简单的xml:2.7.1'){
    排除模块:STAX
    排除模块:STAX-API
    排除模块:XPP3
}
编译(com.google.android.gms:播放服务基地:6.5 +。')
        {
            排除模块:支持-V4
        }
 

有关详细信息,您可以查看本教程的<一个href="https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies">https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

I have an Android project with gradle. The problem is: In project view I see few versions of support-v4 libraries, for example support-v4-21.0.3 and support-v4-22.2.0.

But in build.gradle I don't have support-v4 at all.

But I have ~10 other dependencies in build.gradle. For example appcompat-v7:22.2.0. I can suggests that appcompat-v7:22.2.0 depens on support-v4-22.2.0 in maven dependencies and implicitly pulls it. But I have no ideas who pulls support-v4-21.0.3.

As far as I know all this libs will packed in my APK and increase weight of APK.

So I have next questions:

  1. How to avoid library duplicates?
  2. How to see maven dependencies in Android Studio?
  3. How detect which library require this library? For example which library require support-v4-21.0.3 in my project?

解决方案

To find duplicate dependencies or its required dependencies, you can visualize library dependencies in tree. Execute gradle command as below.

gradle -q dependencies yourProject:dependencies --configuration compile

Note that, run gradlew in Windows as below.

gradlew -q dependencies yourProject:dependencies --configuration compile

The command result will show you human-readable tree hierarchy of all dependencies as below.

compile - Classpath for compiling the main sources.
+--- org.androidannotations:androidannotations-api:3.2
+--- com.android.support:support-annotations:22.1.1
+--- com.squareup:otto:1.3.6
+--- in.srain.cube:grid-view-with-header-footer:1.0.10
+--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- com.github.chrisbanes.photoview:library:1.2.3
+--- org.simpleframework:simple-xml:2.7.1
+--- com.google.android.gms:play-services-base:6.5.+ -> 6.5.87
+--- project :yourProject
|    +--- com.loopj.android:android-async-http:1.4.6
|    +--- org.apache.httpcomponents:httpmime:4.2.5
|    |    \--- org.apache.httpcomponents:httpcore:4.2.4
|    \--- com.google.code.gson:gson:2.3.1
+--- project :facebook
|    \--- com.android.support:appcompat-v7:22.1.1
|         \--- com.android.support:support-v4:22.1.1
|              \--- com.android.support:support-annotations:22.1.1 -> 22.2.0

You can see overriden dependencies and decide in mind which ones should be avoided. In above example, last line com.android.support:support-annotations presents overriden from 22.1.1 to 22.2.0 internally.

To avoid duplicates, you can add exclude clauses in each project build.gradle file.

compile('com.github.chrisbanes.photoview:library:1.2.3') {
    exclude group: 'com.android.support'
}
compile('org.simpleframework:simple-xml:2.7.1') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
}
compile('com.google.android.gms:play-services-base:6.5.+')
        {
            exclude module: 'support-v4'
        }

For more information, you can see the tutorial at https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

这篇关于摇篮 - 依赖关系库复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆