[Gradle 0.7.0] Build fails with: Duplicate files copied in APK META-INF/LICENSE.txt

8,547 views
Skip to first unread message

Patrick Boos

unread,
Dec 19, 2013, 7:55:35 AM12/19/13
to adt...@googlegroups.com
Using commons-io-1.3.2.jar and commons-lang3-3.1.jar together seems to break the build with the error message below.

:app:packageRelease
Error: duplicate files during packaging of APK /Users/whatever/Development/whatever/app/build/apk/app-release-unaligned.apk
Path in archive: META-INF/LICENSE.txt
Origin 1: /Users/whatever/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.3.2/b6dde38349ba9bb5e6ea6320531eae969985dae5/commons-io-1.3.2.jar
Origin 2: /Users/whatever/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.1/905075e6c80f206bbe6cf1e809d2caa69f420c76/commons-lang3-3.1.jar
:app:packageRelease FAILED
 
FAILURE: Build failed with an exception. 

* What went wrong:
Execution failed for task ':app:packageRelease'.
> Duplicate files copied in APK META-INF/LICENSE.txt
  File 1: /Users/whatever/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.3.2/b6dde38349ba9bb5e6ea6320531eae969985dae5/commons-io-1.3.2.jar
  File 2: /Users/whatever/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.3.2/b6dde38349ba9bb5e6ea6320531eae969985dae5/commons-io-1.3.2.jar

Any idea of a quick workaround to fix this?

Cheers,
Patrick 

Patrick Boos

unread,
Dec 19, 2013, 8:00:14 AM12/19/13
to adt...@googlegroups.com
Seems there is already a fix on the way for this:

Patrick Boos

unread,
Dec 19, 2013, 8:15:25 AM12/19/13
to adt...@googlegroups.com
Current workaround from https://code.google.com/p/android/issues/detail?id=61573#c19 :

find ~/.gradle/caches/ -iname "*.jar" -exec zip -d '{}' 'META-INF/NOTICE*' \;
find ~/.gradle/caches/ -iname "*.jar" -exec zip -d '{}' 'META-INF/LICENSE*' \;

Nicolas Milliard

unread,
Dec 19, 2013, 2:44:48 PM12/19/13
to adt...@googlegroups.com
I have the same issue using Dagger and ButteKnife libraries that both use annotation processor:
[DEBUG] [org.gradle.api.Project] => META-INF/services/javax.annotation.processing.Processor
[ERROR] [org.gradle.api.Task] Error: duplicate files during packaging of APK /app/build/apk/app-debug-unaligned.apk
[ERROR] [org.gradle.api.Task] Path in archive: META-INF/services/javax.annotation.processing.Processor
[ERROR] [org.gradle.api.Task] Origin 1: .gradle/caches/modules-2/files-2.1/com.squareup.dagger/dagger-compiler/1.1.0/ddb38c2be31deeb7a001177f7c358665e350d646/dagger-compiler-1.1.0.jar
[ERROR] [org.gradle.api.Task] Origin 2: .gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar

Not sure how to workaround this.

Nicolas

Xavier Ducrohet

unread,
Dec 19, 2013, 4:57:43 PM12/19/13
to adt...@googlegroups.com
oh that's going to be more difficult to deal with, maybe.

I just pused 0.7.1 to central to allow ignore duplicate files, which will not package either of them (which is fine for the typical LICENSE.txt file).

However in this case you have two implementations. If they are needed at runtime, then you may not be able to use both libraries.
If they are not needed then you'll be able to ignore META-INF/services/javax.annotation.processing.Processor and you'll be good.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

David Shen

unread,
Dec 19, 2013, 5:40:25 PM12/19/13
to adt...@googlegroups.com
Hey quick question; if I want to use 0.7.1, I just need to change
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.0' -> 0.7.1
    }
    
Or is there another step? I'm getting an 'artifact not found' error. Thanks! 

Jake Wharton

unread,
Dec 19, 2013, 5:45:35 PM12/19/13
to adt...@googlegroups.com
They're needed in javac at compile-time but not at runtime. As long as the filtering happens at the end of the pipeline (packaging, look like) you should be good.

Xavier Ducrohet

unread,
Dec 19, 2013, 5:50:46 PM12/19/13
to adt...@googlegroups.com
Yeah the filtering happens when we packaged the non class files from the jars inside the APK, so it should be fine to ignore them then.

Xavier Ducrohet

unread,
Dec 19, 2013, 5:52:03 PM12/19/13
to adt...@googlegroups.com
That's all you need. MavenCentral may still be replicating, I'm not sure.

I don't see the artifacts on search.maven.org but I was able to build the samples (even after cleaning all of my local caches).

Nicolas Milliard

unread,
Dec 19, 2013, 6:23:57 PM12/19/13
to adt...@googlegroups.com
I update 0.7.1 and it failed at first with : 
-------------------------------------------------------------------
Error: duplicate files during packaging of APK app/build/apk/app-debug-unaligned.apk
Path in archive: META-INF/services/javax.annotation.processing.Processor
Origin 1: /home/niqo/.gradle/caches/modules-2/files-2.1/com.squareup.dagger/dagger-compiler/1.1.0/ddb38c2be31deeb7a001177f7c358665e350d646/dagger-compiler-1.1.0.jar
Origin 2: /home/niqo/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar
You can ignore those files in your build.gradle:
android {
 packagingOptions {
   exclude 'META-INF/services/javax.annotation.processing.Processor'
 }
}
-------------------------------------------

Adding the recommanded build config worked!

Thanks for this fast fix.

niColas

Xavier Ducrohet

unread,
Dec 19, 2013, 6:24:52 PM12/19/13
to adt...@googlegroups.com
Glad to hear!

Traun Leyden

unread,
Dec 19, 2013, 8:07:26 PM12/19/13
to adt...@googlegroups.com

I am getting this error with Android Studio 0.4:

Error: duplicate files during packaging of APK /Users/traun/Development/couchbase-lite-android/CouchbaseLiteProject/CBLite/build/apk/CBLite-debug-test-unaligned.apk
Path in archive: META-INF/ASL2.0
Origin 1: /Users/traun/.gradle/caches/modules-2/files-2.1/org.codehaus.jackson/jackson-mapper-asl/1.9.2/95400a7922ce75383866eb72f6ef4a7897923945/jackson-mapper-asl-1.9.2.jar
Origin 2: /Users/traun/.gradle/caches/modules-2/files-2.1/org.codehaus.jackson/jackson-core-asl/1.9.2/8493982bba1727106d767034bd0d8e77bc1931a9/jackson-core-asl-1.9.2.jar
You can ignore those files in your build.gradle:
android {
 packagingOptions {
   exclude 'META-INF/ASL2.0'
 }
}
:CBLite:packageDebugTest FAILED

and I tried adding the packagingOptions directive (here is my entire build.gradle file: https://gist.github.com/tleyden/8048897)

but now it's giving me this error:

* Where:
Build file '/Users/traun/Development/couchbase-lite-android/CouchbaseLiteProject/CBLite/build.gradle' line: 38

* What went wrong:
A problem occurred evaluating project ':CBLite'.
> Could not find method packagingOptions() for arguments [build_7e8h4gb29m24saphgjk26o3v1r$_run_closure3_closure10@6c80d028] on project ':CBLite'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Any ideas?

Xavier Ducrohet

unread,
Dec 19, 2013, 8:14:35 PM12/19/13
to adt...@googlegroups.com
ah that's because it's only for applications, not libraries, because libraries don't package their dependencies.

However test apps for libraries do... sigh. In my hurry to push a fix, I forgot about that. I'll push a 0.7.2 tomorrow.

Noot

unread,
Dec 22, 2013, 6:07:57 PM12/22/13
to adt...@googlegroups.com
Hi Xavier,

Did you push 0.7.2? I still cannot solve this issue.

Xavier Ducrohet

unread,
Dec 23, 2013, 2:42:38 AM12/23/13
to adt...@googlegroups.com
Not yet. I'm going to try to push it tomorrow.

Scott Battaglia

unread,
Dec 24, 2013, 9:16:03 AM12/24/13
to adt...@googlegroups.com
Xavier,

Were you able to push it?  I didn't see it available when I checked in search.maven.org

Thanks
Scott

Xavier Ducrohet

unread,
Dec 24, 2013, 3:50:17 PM12/24/13
to adt...@googlegroups.com
Sorry, I ended up spending more time than I planned fixing some issues. My current plan is Thursday.

Pete Cornish

unread,
Dec 27, 2013, 7:21:20 PM12/27/13
to adt...@googlegroups.com
Hi Xavier,

Is there any progress on an updated Gradle plugin to resolve this issue in 0.7.x?

For reference, I can reproduce this with the following config:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.1'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.android.gms:play-services:3.2.25'
    compile 'com.android.support:support-v4:18.0.0'
    compile 'commons-io:commons-io:2.4'
    compile 'commons-lang:commons-lang:2.6'
}

I am using the recommended Gradle wrapper config from Android Studio (Gradle v1.9). The error message is very similar to Patrick's:

:packageRelease
Error: duplicate files during packaging of APK /Users/pc/android-projects/example/build/apk/example-release-unaligned.apk
Path in archive: META-INF/LICENSE.txt
Origin 1: /Users/pc/.gradle/caches/modules-2/files-2.1/commons-lang/commons-lang/2.6/ce1edb914c94ebc388f086c6827e8bdeec71ac2/commons-lang-2.6.jar
Origin 2: /Users/pc/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.4/b1b6ea3b7e4aa4f492509a4952029cd8e48019ad/commons-io-2.4.jar
You can ignore those files in your build.gradle:
android {
 packagingOptions {
   exclude 'META-INF/LICENSE.txt'
 }
}
:packageRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':packageRelease'.
> Duplicate files copied in APK META-INF/LICENSE.txt
  File 1: /Users/pc/.gradle/caches/modules-2/files-2.1/commons-lang/commons-lang/2.6/ce1edb914c94ebc388f086c6827e8bdeec71ac2/commons-lang-2.6.jar
  File 2: /Users/pc/.gradle/caches/modules-2/files-2.1/commons-lang/commons-lang/2.6/ce1edb914c94ebc388f086c6827e8bdeec71ac2/commons-lang-2.6.jar

Adding the packaging exclusion as suggested by the error message does work as a workaround.

Please do get in touch if you'd like more info or would like me to verify any potential fixes.

All the best,

Pete

Xavier Ducrohet

unread,
Dec 28, 2013, 1:30:10 AM12/28/13
to adt...@googlegroups.com
I'm not sure what the problem is.

Add 

android {
  packagingOptions {
    exclude 'META-INF/LICENSE.txt'
  }
}

to your build.gradle to make it exclude the conflicting file. This fix is present in 0.7.1+

Simon Vig Therkildsen

unread,
Dec 28, 2013, 8:52:58 PM12/28/13
to adt...@googlegroups.com
Is it a change in gradle or in the android plugin that requires us to explicitly exclude these files now?

Curtis Schwoebel

unread,
Dec 30, 2013, 5:55:52 AM12/30/13
to adt...@googlegroups.com
Hello, 

When I start using gradle 0.7.3 and apply this workaround I start getting the error: Lint: problems would in abortOnError = false.  Aborting build.  There was a workaround suggested for that, but it starts down a long road of error messages and workarounds that never get anywhere good.

Tor Norbye

unread,
Dec 30, 2013, 12:25:46 PM12/30/13
to adt...@googlegroups.com
On Mon, Dec 30, 2013 at 2:55 AM, Curtis Schwoebel <curtis.s...@gmail.com> wrote:
Hello, 

When I start using gradle 0.7.3 and apply this workaround I start getting the error: Lint: problems would in abortOnError = false.  Aborting build.  There was a workaround suggested for that, but it starts down a long road of error messages and workarounds that never get anywhere good.

Not sure what you mean by "never get anywhere good", but that error message tells you that  (1) you ran the check task, which as of 0.7 also runs the lint task, and (2) lint found issues that had severity error, and (3) lint has been instructed to halt the build if it finds one or more errors. This is the default. Before the error message there should be output from lint pointing to a lint HTML report which pinpoints the issues it found. Take a look and see if they are real errors you should fixing.

If you want to run the check task but to not have errors fail the build, you can add

android {
    lintOptions {
        abortOnError false
    }
}


-- Tor
Reply all
Reply to author
Forward
0 new messages