I am trying to remove the transitive dependencies from my Android project and for some reason exclude
is not working when i try to remove a dependency from my particular dependency.
For example i want to remove support-annotations
from my project
if i use
configurations {
all*.exclude group: 'com.android.support', module:'support-annotations'
}
The dependency gets excluded and from the dependency tree. i can see the dependency tree by using ./gradlew app:dependencies
But if i use
compile('com.android.support:support-v4:23.4.0')
{
exclude group: 'com.android.support', module:'support-annotations'
}
Then i still see the dependency in the dependency tree.
So my question is that why is it not working when i try to remove the dependency from a particular dependency ?
Update 1:
Also can anyone tell me what does the star
(*) symbol next to dependency in the tree represent ?
Update 2
I am also using Fresco I tried the same thing with Fresco and exclude
rule seems to work for it
Dependency Tree of Fresco
Dependency Tree when i exclude imagepipeline-base
in Fresco
compile("com.facebook.fresco:fresco:0.9.0")
{
exclude group: 'com.facebook.fresco', module: 'imagepipeline-base'
}
As you can see the imagepipeline-base
dependency gets excluded. So i don't know why this doesn't work for Android Support Annotations transitive dependency
So i have figured this out with the help of one of my friends. The reason why i was not able to remove support-annotation
was because most of the other dependencies were using support-v4
as transitive dependency and those support-v4
also had their own copy of support-annotation
.
Now there are 2 solutions to this
Solution 1:
exclude support-annotation
from all the dependencies that containsupport-v4
as transitive dependency.
Solution 2:
exclude support-annotation
only from my support-v4
dependency and remove support-v4
dependency from all other dependencies that have support-v4
as transitive dependency.
Note: Using one of the above approaches i was able to solve my problem and figure out how we can remove transitive dependencies when they are referenced from multiple dependencies.
And regarding the ( * ) symbol it means that the dependency tree is for that dependency is already shown. Instead of showing the whole tree for those dependencies again gradle shows ( * ) symbol with them.
Sample build.gradle
file is available here