Gradle faces problems with merging of .jars when multiple are found.
Turns out, that Gradle has annoying issue with packaging dependencies.When there are multiple sources where gradle can grab .jar dependency, it fails to merge meta files, like here, when 2 commons-io jars are present in cache:
* What went wrong:
Execution failed for task ':app:release'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/commons-io/commons-io/pom.xml
File1: /home/user/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.3.2/b6dde38349ba9bb5e6ea6320531eae969985dae5/commons-io-1.3.2.jar
File2: /home/user/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-io/1.3.2/b6dde38349ba9bb5e6ea6320531eae969985dae5/commons-io-1.3.2.jar
To fix this issue one should add packaging options to build.gradle
packagingOptions {
exclude 'META-INF/maven/commons-io/commons-io/pom.xml'
exclude 'META-INF/maven/commons-io/commons-io/pom.properties'
}