Error: Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]

Error: Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]

问题:

升级到 Android Studio 3 后出错:Error:java。io.IOException:重复的 zip 条目 [43.jar:org/apache/http/annotation/NotThreadSafe。 class]

如果您能帮助解决问题,我们将不胜感激。似乎与 apache 库或其他东西有关,不确定注释是什么。此设置在 Android 2.3 上运行良好,因为我更新后收到此错误并且已经花费数小时试图解决此问题。我已经启用了 multidex 支持,但似乎这需要更具体的修复。干杯

刚刚更新为 androidStudio3。不幸的是,当我 运行 构建时,出现以下 4 个错误:

Error:java.lang.RuntimeException: java.io.IOException: Can't write [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]))

Error:java.io.IOException: Can't write [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]))

Error:java.io.IOException: Can't read [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class])

Error:java.io.IOException: Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]

更详细的异常:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access0(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.RuntimeException: java.io.IOException: Can't write [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]))
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.run(ExecuteActionsTaskExecuter.java:122)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 27 more
Caused by: java.io.IOException: Can't write [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]))
    at proguard.OutputWriter.writeOutput(OutputWriter.java:187)
    at proguard.OutputWriter.execute(OutputWriter.java:79)
    at proguard.ProGuard.writeOutput(ProGuard.java:427)
    at proguard.ProGuard.execute(ProGuard.java:175)
    at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:61)
    at com.android.build.gradle.internal.transforms.MainDexListTransform.shrinkWithProguard(MainDexListTransform.java:232)
    at com.android.build.gradle.internal.transforms.MainDexListTransform.transform(MainDexListTransform.java:184)
    at com.android.build.gradle.internal.pipeline.TransformTask.call(TransformTask.java:222)
    at com.android.build.gradle.internal.pipeline.TransformTask.call(TransformTask.java:218)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 39 more
Caused by: java.io.IOException: Can't read [C:\Users\MICHAEL\AndroidStudioProjects\Project\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class])
    at proguard.InputReader.readInput(InputReader.java:188)
    at proguard.InputReader.readInput(InputReader.java:158)
    at proguard.OutputWriter.writeOutput(OutputWriter.java:176)
    ... 48 more
Caused by: java.io.IOException: Duplicate zip entry [43.jar:org/apache/http/annotation/NotThreadSafe.class]
    at proguard.io.JarWriter.getOutputStream(JarWriter.java:138)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:106)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:106)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:92)
    at proguard.io.ClassRewriter.read(ClassRewriter.java:68)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.JarReader.read(JarReader.java:65)
    at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:65)
    at proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:53)
    at proguard.InputReader.readInput(InputReader.java:184)
    ... 50 more

这是我的 build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.example.michael.project"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        jackOptions {
            enabled true
        }

        // Enabling multidex support.
        multiDexEnabled true
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }

    lintOptions {
        checkReleaseBuilds false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.google.api-client:google-api-client-android:1.22.0'
    compile 'com.google.apis:google-api-services-vision:v1-rev357-1.22.0'
    compile 'com.google.code.findbugs:jsr305:2.0.1'
    compile 'commons-io:commons-io:2.5'
    compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    compile 'com.android.support:appcompat-v7:26+'
    compile 'com.android.support:design:26+'
    compile 'com.android.support:recyclerview-v7:26+'
    compile 'com.android.support:cardview-v7:26+'
    compile 'com.synnapps:carouselview:0.1.4'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/fluent-hc-4.5.3.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/jna-4.1.0.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/jna-platform-4.1.0.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/jsoup-1.10.3.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/commons-cli-1.2.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/org-apache-commons-codec.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/jaunt1.3.5.1.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/commons-lang3-3.6.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/unirest-java-1.4.9.jar')
    compile files('C:/Users/MICHAEL/AndroidStudioProjects/Project/lib/urlimageviewhelper-1.0.4.jar')
}

通过删除

解决了问题
jackOptions {
    enabled true
}

并添加

android.compileOptions.sourceCompatibility 1.8
android.compileOptions.targetCompatibility 1.8

此外,删除了所有本地导入的 apache jar 并替换为这些:

compile 'commons-codec:commons-codec:1.10'
compile 'org.apache.commons:commons-lang3:3.6'
compile 'commons-io:commons-io:2.6'
compile('org.apache.httpcomponents:httpmime:4.3.6') {
    exclude module: 'httpclient'
}

清理并重建了项目,谢天谢地,现在可以正常工作了。