Commons-Io Duplicate Entry Error Using Robospice and Android Studio
Asked Answered
K

2

4

I've been working on the following issue for several hours, but haven't come up with a way to solve my problem. I've tried the following fixes from Stack Overflow (Android Studio update to 1.0 corrupts MultiDex and Duplicate Zip Entry after Gradle Plugin v0.13.1) but neither one of them worked.

I am getting the following error when trying to build my program:

Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: org/apache/commons/io/CopyUtils.class

The error seems to indicate that commons-io is being included twice in the build process

I am using Android Studio and Gradle to include multiple Robospice dependencies. This is the dependencies section of my Gradle build file:

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'

    compile'com.google.api-client:google-api-client-android:1.19.0'


    // You must install or update the Google Repository through the SDK manager to use this dependency.
    // The Google Repository (separate from the corresponding library) can be found in the Extras category.
    //compile 'com.google.android.gms:play-services:4.3.23'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.jakewharton:butterknife:${butterknifeVersion}"
    compile 'com.sun.jersey:jersey-bundle:1.8'
    compile 'com.google.code.gson:gson:2.3'
    compile 'org.codehaus.jackson:jackson-core-asl:1.9.0'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.0'

    compile ('com.octo.android.robospice:robospice:1.4.14'){
        exclude module: 'commons-io'
        exclude group: 'commons-io'
    }

    compile ('com.octo.android.robospice:robospice-spring-android:1.4.14'){
        exclude group: 'org.apache.commons', module: 'commons-io'
    }

    compile 'com.squareup.okhttp:okhttp:2.1.0'

    compile ('com.octo.android.robospice:robospice-google-http-client:1.4.14'){
        exclude module: 'xpp3'
        exclude group: 'stax'
    }

    compile 'org.scribe:scribe:1.3.5'
    compile files("$buildDir/native-libs/native-libs.jar")

}

Using the "gradlew -q dependencies app:dependencies" command to view the project's dependency tree indicates that com.octo.android.robospice:robospice:1.4.14 is dependent on the commons-io library. Here is the relevant snippet of the project dependency tree:

+--- com.octo.android.robospice:robospice:1.4.14
|    \--- com.octo.android.robospice:robospice-cache:1.4.14
|         +--- org.apache.commons:commons-lang3:3.3.2
|         \--- org.apache.commons:commons-io:1.3.2
|              \--- commons-io:commons-io:1.3.2

The dependency is still listed even though I excluded commons-io from all Robospice related dependencies in the gradle build file. I also tried changing the group name from commons-io to org.apache.commons, and that did not work either.

My project is at a standstill until I get this resolved, and I would appreciate any help I can get.

Kiddush answered 2/1, 2015 at 17:0 Comment(1)
This answer may be helps to solve your problem Answer_LinkAgama
I
11

This is a known and fixed problem in Robospice, caused by an underlying Gradle 2.1 issue: https://github.com/stephanenicolas/robospice/issues/365. The fix is going to be released in the next version.

You can work around it by excluding org.apache.commons:commons-io from all Robospice dependencies, and include commons-io:commons-io:1.3.2 manually. Like this:

// workaround (https://github.com/stephanenicolas/robospice/issues/365)
// remove when robospice updates to 1.4.15+
compile ('com.octo.android.robospice:robospice-retrofit:1.4.14') {
    exclude group: 'org.apache.commons', module: 'commons-io'
}
compile ('com.octo.android.robospice:robospice-ormlite:1.4.14') {
    exclude group: 'org.apache.commons', module: 'commons-io'
}
compile 'commons-io:commons-io:1.3.2'
Indicatory answered 2/1, 2015 at 18:54 Comment(4)
Yep, that worked. I saw that linked, but I guess I never fully implemented that solution.Kiddush
@Indicatory I Am getting Gradle DSL method not found: 'complie()' when I do this. I need urgent help please!Pulsation
See #27618187 about that problem.Indicatory
@Indicatory I am afraid that is not my case, could you please take a look at my question? #31857203Pulsation
T
1

I guess this question needs a structured approach towards solving the issue which both of the above answers fail to provide.

Step 1: Find out which external library is causing duplicate zip entry. Run following command from terminal of Android Studio. gradlew -q dependencies app:dependencies

In my case, image picking library ('net.yazeed44.imagepicker:imagepicker:1.3.0') was causing the duplicate entry.

Step 2: Add code to exclude commons-io only for that library

compile ('net.yazeed44.imagepicker:imagepicker:1.3.0'){
        exclude group: 'org.apache.commons', module: 'commons-io'
}  

Step 3: Include updated commons-io library. compile 'commons-io:commons-io:1.3.2'

Now you are set to go.

Tamelatameless answered 1/4, 2017 at 22:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.