要查找重复的依赖项或其所需的依赖项,您可以在树中可视化库依赖项。如下执行gradle命令。
gradle -q dependencies yourProject:dependencies --configuration compile
请注意,在 Windows 中运行gradlew,如下所示。
gradlew -q dependencies yourProject:dependencies --configuration compile
命令结果将显示所有依赖项的人类可读树层次结构,如下所示。
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
您可以查看被覆盖的依赖项并决定应该避免哪些依赖项。在上面的示例中,最后一行 com.android.support:support-annotations 表示内部从 22.1.1 覆盖到 22.2.0。
为避免重复,您可以在每个项目build.gradle文件中添加exclude子句。
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'
}
更多信息,您可以在https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies查看教程