androidgradleandroid-studiorobospiceapache-commons-io

Commons-Io Duplicate Entry Error Using Robospice and Android Studio


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.


Solution

  • 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'