Android Gradle commons-io compilation duplicates in library tree

I am trying to create and maintain an old application to work, but I cannot go through the build phase. In my app/build.gradle , I have

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.apache.commons:commons-io:1.3.2' //some more libraries compiled as well } 

but when trying to execute the following error:

Error: execution completed for task ': myApp'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org / apache / commons / io / CopyUtils.class

This is almost certainly because when I compile this jar at the top of my external library tree, this is generated:

enter image description here

Why is this happening, and how can I make it stop in order to complete the assembly?

+5
source share
4 answers

There is an easy way to exclude double classes. First you need to find out which dependency causes this if you know you are using this code:

 compile('com.example:some-dependency:4.2') { exclude module: 'commons-io' } 
+5
source

It is possible to fix it at the gradle permission level

 configurations.all { resolutionStrategy.dependencySubstitution { substitute module('org.apache.commons:commons-io:1.3.2') with module('commons-io:commons-io:1.3.2') } } 

The reason for the conflict is that org.apache.commons:commons-io:1.3.2 was mistakenly made by fooobar.com/questions/430447 / ...

You can see where the dependency comes from:

gradle :main:dependencyInsight --configuration compile --dependency commons-io

+10
source

I know that this thread is quite old, but if someone encounters this problem, the reason may be in the artifact itself.

com.apache.commons:commons-io:XXX been moved to commons-io:commons-io:XXX , and retrieving an old artifact may lead to unexpected behavior.

+5
source

It is possible that other project libraries have a common dependency that causes duplicate entries.

See if it helps - Gradle Duplicate entry: java.util.zip.ZipException

+1
source

Source: https://habr.com/ru/post/1242230/


All Articles