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
When you specify a dependency in your build script, you can provide an exclude rule at the same time telling Gradle not to pull in the specified transitive dependency. For example, say we have a Gradle project that depends on Google's Guava library, or more specifically com. google. guava:guava:30.1.
If a transitive dependency exists, we remove the transitively dependent attribute(s) from the relation by placing the attribute(s) in a new relation along with a copy of the determinant.
To override the version of a transitive dependency in Gradle, exclude it from the declared dependency that pulls it in, and then explicitly declare the version that you prefer to use in your build.
Gradle automatically resolves those additional modules, so called transitive dependencies. If needed, you can customize the behavior the handling of transitive dependencies to your project's requirements. Projects with tens or hundreds of declared dependencies can easily suffer from dependency hell.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With