java.util.zip.ZipException: duplicate entry: andro

2019-02-15 22:33发布

问题:

I'm new to android studio and am trying to import a project from eclipse but I feel like i am running into every single problem possible. The error I'm currently getting is:

Error:Execution failed for task ':jobFlexwithInvoice:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/view/MotionEventCompatEclair.class

Ive seen similar answers to problems like here and here. But i think I need more help because its just not going away. I've added the exception to just about everything in my build.gradle file, including the actual support 4v dependency just for kicks, and am still getting this error. And also I have multiple build.gradle files because of included projects? It seems like the project build.gradle file can be ignored, I just have to add the exceptions to the module build.gradle files? (which is annoying when someone says to add something to the build.gradle file, im not always sure which one)

Anyway, here are the dependencies sections of each of my build.gradle files as they currently are:

myApp:

dependencies {
    compile ('com.android.support:multidex:1.0.0'){
        exclude module: 'support-v4'
    }
    compile project(':facebook') {
        exclude module: 'support-v4'
    }
    compile project(':apptentive')
    compile project(':androidsdkui'){
        exclude module: 'support-v4'
    }
    compile ('com.google.android.gms:play-services:+'){
        exclude module: 'support-v4'
    }
    compile files('libs/android-support-v13.jar') {
        exclude module: 'support-v4'
    }
    compile files('libs/DynamicPDF.jar')
    compile files('libs/picasso-2.5.0.jar')
    compile ('com.android.support:support-v4:22.0.0'){
        exclude module: 'support-v4'
    }
}

facebook:

dependencies {
    compile files('libs/bolts-android-1.2.1.jar')
    compile ('com.android.support:support-v4:22.0.0'){
        exclude module: 'support-v4'
    }
}

androidsdkui:

dependencies {
    compile files('libs/appboy.jar')
    compile ('com.android.support:support-v4:22.0.0'){
        exclude module: 'support-v4'
    }
}

there is also an apptentive build.gradle file but it does not have any dependencies. Before adding all of these exceptions I was getting the same error as the one in the first link, now the only difference is its android/support/v4/view/MotionEventCompatEclair.class instead of android/support/v4/util/TimeUtils.class

If there is a way to see where the duplicates are coming from that would be great too, I was unable to find anything with a quick google search.

回答1:

I updated the question so you can see some of the ways I was doing things wrong. Some of my projects included support v4 and I wasn't excluding them right. The proper way to exclude things from projects is:

compile (project(':facebook')) {
    exclude module: 'support-v4'
}

you have to put the extra set of parenthesis around everything after compile. Im assuming the same goes for excluding things from files

ie.

compile file(myfile.jar)

would become

compile (file(myfile.jar)) { 
    exclude module: 'support-v4'
}


回答2:

Could you try adding the following in the top-level build.gradle file inside allprojects element? It should look something like below.

allprojects {
    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
    }
}

Hope this helps.