9

When compiling my app, I get the following error (sensitive pieces of path edited out)

Execution failed for task ':app:proguardDebug'.
> java.io.IOException: Can't write [/projects/app/build/intermediates/classes-proguard/debug/classes.jar] (Can't read [/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.4/4216af16d38465bbab0f3dff8efa14204f7a399a/commons-codec-1.4.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [commons-codec-1.4.jar:org/apache/commons/codec/binary/Base64.class]))

This indicates to me that the compiler sees two places where the app is trying to use commons.codec.binary.Base64.class as a dependency. I have checked and checked my libraries again, but only one library (Amazon AWS) is attempting to use it.

Above this error, I'm getting some other warnings which also raise a red flag for me:

Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-lang3-3.1.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-lang3-3.1.jar:META-INF/NOTICE.txt])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-codec-1.4.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-codec-1.4.jar:META-INF/NOTICE.txt])

I don't explicitly use commons-codec-1.4 or commons-lang3-3.1 in my app at all, thought I used to use lang3 before later removing it. Why are these being referenced in the compile log? Could one of my maven libraries be using them? I'll include a list of maven libraries below in my gradle file.

Here are my proguard and gradle files for reference:

PROGUARD

-keep class org.w3c.dom.bootstrap.** { *; }
-keep class org.joda.time.** { *; }
-keep class com.facebook.** { *; }
-keep class org.apache.commons.** { *; }
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontwarn org.codehaus.jackson.map.ext.**
-dontwarn oauth.**
-dontwarn com.amazonaws.**
-dontwarn org.joda.time.**
-dontwarn org.apache.commons.codec.**
-dontwarn com.fasterxml.jackson.databind.ext.**

GRADLE

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId 'com.my.package'
        minSdkVersion 14
        targetSdkVersion 20
        versionCode 9
        versionName '1.2'
    }

    buildTypes {
        release {
            debuggable false
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        checkReleaseBuilds false
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/MANIFEST.MF'
    }
}

dependencies {
    compile fileTree(dir: 'libs',  include: ['*.jar'])

    //noinspection GradleDependency
    compile 'com.google.android.gms:play-services:5.0.89'

    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
    compile 'se.emilsjolander:stickylistheaders:2.5.0'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
    compile project(':facebook')
    compile 'com.tumblr:jumblr:0.0.10'
    compile 'com.android.support:support-v4:20.0.0'
}

My best guess is one or more of those libraries is using apache lang3 and codec as dependencies of their own, which is resulting in a conflict when I compile the app. This problem only happens when I include Amazon as a required jar, so I know that is in some way acting as the culprit, but I don't know what else is conflicting with it.

I read something about using -injars with proguard, but according to their documentation Android shouldn't need you to use that.

Any advice would be greatly appreciated, thanks!

3
  • If you want some more information on what is causing these transitive dependencies you can ask Gradle by running gradlew dependencyInsight --dependency=commons-lang3. Commented Sep 5, 2014 at 4:40
  • I am having a similar issue. The compilation process can finish without errors, but I do get those META-INF related warnings
    – Guilherme
    Commented Sep 9, 2014 at 13:22
  • I am having the same error only on the universal image loader. Any luck?
    – akousmata
    Commented May 18, 2015 at 15:09

2 Answers 2

3

I am not sure if this will help you or not but I am posting my answer here in case others find this useful. My issue was that I had 2 references in my dependencies statement. I was using the Universal Image Loader library and my statement looked like this:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:support-v4:22.1.1'
    compile 'uk.co.chrisjenx:calligraphy:2.0.2'
    /* UIL was the failing reference */
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.google.android.gms:play-services:7.3.0'
}

The problem with this I realized (after a head smack moment) was that I had already referenced UIL via the libs folder (i.e. it was already being compiled by the statement compile fileTree(dir: 'libs', include: ['*.jar']). So it was compiling it once via libs and once via the explicit call to compile the reference to UIL. I removed the explicit call and that cleared up the error. Perhaps you are calling something in your libs directory that also contains a reference to the offending library then when it tries to compile the AWS Services it already has a version of the commons library and pukes.

0

The cause of this problem is the duplication of jar files.

In your project directory, try finding and erasing

/projects/app/build/intermediates/classes-proguard/debug/classes.jar] (Can't read[/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.4/4216af16d38465bbab0f3dff8efa14204f7a399a/commons-codec-1.4.jar

this jar file and see if anything changes. Also, if there is commons-lang3-3.1.jar in the same or upper dirrectory, try erasing that and rebuilding as well.

Hope it helps!

2
  • The problem is when I try something like this, upon the next gradle build it is readded to the directory. Commented Oct 28, 2014 at 21:39
  • humm... I think that's because either you are specifying somewhere that the project requires that jars, or
    – Shawn
    Commented Oct 29, 2014 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.