7

I've been looking around at some of the answers posted here about this error but have had no luck. I'm hoping to get some clarification about what's going on. my error is as follows:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. 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/colin/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-io/1.3.2/b6dde38349ba9bb5e6ea6320531eae969985dae5/commons-io-1.3.2.jar File2: /home/colin/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.3.2/b6dde38349ba9bb5e6ea6320531eae969985dae5/commons-io-1.3.2.jar

I've done

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
}

in the app > build.gradle file, but the problem persists. Is there somewhere else I should put this, or perhaps just delete some file? Or perhaps I've excluded too many files - Should I omit some of these lines, and if so which ones? I also tried moving the dependencies in to the top, above Android to no avail.

Furthermore I'm a little confused about some of the advice given in these posts. What is the operating difference between Exclude and PickFirst? They seem to be interchangeable but express very different ideas. It seems I'm required to include a license when uploading to the app store, so if I'm excluding it here in order to get the app to compile, where do I include it later on when I'm ready to upload? I hope someone can shed some more light on what's going on here.

Community
  • 1
  • 1
Csteele5
  • 1,262
  • 1
  • 18
  • 36

1 Answers1

14

I had to add the following lines to packagingOptions {}

exclude 'META-INF/maven/commons-io/commons-io/pom.xml'
exclude 'META-INF/maven/commons-io/commons-io/pom.properties'

My problem was pretty foolish; when including exclude 'META-INF/maven/commons-io/commons-io/pom.xml' I got an error that looked very similar to the first one, but was in fact different. adding exclude 'META-INF/maven/commons-io/commons-io/pom.properties' finally got everything working. Still not sure why exactly I have to take these steps though.

Csteele5
  • 1,262
  • 1
  • 18
  • 36
  • No problem! I'm comforted by the fact that so many other people have encountered this trivial problem as well :P – Csteele5 May 17 '16 at 18:52
  • Facing same issue. when adding `compile 'org.apache.commons:commons-io:1.3.2'`. Do you know why `commons-io` and `org.apache.commons` are both included?? They seem to be the same stuff. – Weishi Z Aug 05 '16 at 01:49
  • If I recall I remember really thinking they were the same thing coming from two different libraries. I never found out why this happened. – Csteele5 Aug 05 '16 at 01:50
  • 1
    My guess is org.apache.commons:commons-io was renamed to commons-io:commons-io and org.apache.commons:commons-io now acts as a "symbolic link". There's nothing inside it but it has a dependency on commons-io:commons-io which holds the actual code. – Eugen Pechanec Sep 19 '16 at 12:36