【问题标题】:java.util.zip.ZipException: duplicate entry: org/apache/http/ConnectionClosedException.classjava.util.zip.ZipException:重复条目:org/apache/http/ConnectionClosedException.class
【发布时间】:2016-03-02 09:18:02
【问题描述】:

我在运行应用程序时遇到这样的错误。我在 MainActivity 中使用 HttpClient、HttpEntity、HttpResponse 和 HttpPost..所以我对 gradle 文件进行了一些修改。之后我收到这样的错误。

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/ConnectionClosedException.class

我还在我的应用程序中包含了 multidex 库和 org.apache.http.legacy.jar。但是我也遇到了同样的错误。

build.gradle

apply plugin: 'com.android.application'

android {


    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.test1"
        minSdkVersion 15
        targetSdkVersion 23
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:multidex:1.0.1'
    compile files('libs/org.apache.http.legacy.jar')
    compile 'org.apache.httpcomponents:httpmime:4.5.1'
}

我知道这个问题已经被问过很多次了,但是没有一个解决方案对我有用.. 谁能帮我解决这个问题。

【问题讨论】:

  • 您正在添加此类 org/apache/http/ConnectionClosedException 两次。检查你的依赖关系。
  • 我检查了..我只添加了一次..甚至我在依赖项中评论了compile files('libs/org.apache.http.legacy.jar')这一行,因为我已经将 jar 文件复制到了 libs 文件夹中..但是我也遇到了同样的错误.
  • @GabrieleMariotti 可能是什么问题..?

标签: android-studio android-gradle-plugin android-support-library android-multidex


【解决方案1】:

您不能同时使用“compile 'org.apache.httpcomponents:httpcore:4.4.1'”和“compile files('libs/org.apache.http.legacy.jar')”。

【讨论】:

  • 您能详细说明一下吗?那么解决办法是什么?
【解决方案2】:

我也遇到了同样的问题。问题是因为你在使用

compile files('libs/org.apache.http.legacy.jar') and
compile 'org.apache.httpcomponents:httpmime:4.5.1'

您需要删除我在下面提到的两个库。其中包含上述内容的重复。

if you are adding legacy and httpmime you don't need this
        compile 'org.apache.httpcomponents:httpcore:4.4.1'//remove this
        compile 'org.apache.httpcomponents:httpclient:4.5' // remove this too

在 gradle 的 android 部分也添加这个

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    useLibrary 'org.apache.http.legacy'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多