【问题标题】:Android httpcore, httpmime and httpclient-android libraries import givs an errorAndroid httpcore、httpmime 和 httpclient-android 库导入会报错
【发布时间】:2016-05-04 03:30:20
【问题描述】:

在我的 Android 中,我要上传一个文件到后端服务器,并考虑使用 HTTP post request using MultipartEntity >。在这种情况下,我首先添加了 httpcorehttpmime 库,但它给了我一个错误。所以经过一番谷歌搜索后,我发现 httpclient-android 也必须导入。所以最后我的 build.gradle 文件如下所示。

android {
    compileSdkVersion 'Google Inc.:Google APIs:21'
    buildToolsVersion '23.0.2'
    defaultConfig {
        applicationId "com.m.l"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 69
        versionName '2.0.15'
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile project(':holoColorPickermaster')
    compile project(':qRCodeReaderViewlib')
    compile project(':volley')
    compile project(':library')
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:multidex:'
    compile 'org.apache.httpcomponents:httpcore:4.4.4'
    compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
}

但现在当我运行应用程序时,它会提示我不同的错误。我的错误日志如下,

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

我在网络上查找此错误并尝试修复它。但没有得到适当的解决方案。发现这是由重复文件引起的。我怎样才能解决这个问题。谢谢和问候。

【问题讨论】:

    标签: java android http


    【解决方案1】:

    如果您有一些不想编译的源代码,您必须为这些源代码声明一个过滤器,而不是为放入 Jar 中的类文件声明一个过滤器。比如:

    sourceSets {
        main {
            java {
                include 'com/ourcompany/somepackage/activityadapter/**'
                include 'com/ourcompany/someotherpackage/**'
                exclude 'com/ourcompany/someotherpackage/polling/**'
            }
        }
    }
    

    如果你不想编译这些包,这个解决方案是有效的,但如果你想编译它们并从你的 JAR 中排除,你可以使用

    jar {
        exclude('mi/package/excluded/**')   
        exclude('mi/package/excluded2/**')  
    }
    

    【讨论】:

    • 感谢您的快速回复。就我而言,它在错误中显示“重复条目:org/apache/http/concurrent/BasicFuture.class”。我怎样才能找到要排除的,只要它们属于图书馆???????
    猜你喜欢
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2015-11-17
    • 1970-01-01
    相关资源
    最近更新 更多