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:
- How to avoid library duplicates?
- How to see maven dependencies in Android Studio?
- 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.
Note that, run
gradlew
in Windows as below.The command result will show you human-readable tree hierarchy of all dependencies as below.
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 from22.1.1
to22.2.0
internally.To avoid duplicates, you can add
exclude
clauses in each projectbuild.gradle
file.For more information, you can see the tutorial at https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies
The following android studio plugin gives you details about the duplicate dependencies and total method count of each dependencies. Android Methods Count Plugin