将httpcore和httpmime库添加到Android项目会在运行该应用程序时出现错误 [英] Adding httpcore and httpmime libraries to Android project gives an error in running the app

查看:198
本文介绍了将httpcore和httpmime库添加到Android项目会在运行该应用程序时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中,我正在使用httpcore和httpmime库。我的build.gradle文件依赖项部分包含以下部分,

In my Android app I'm using httpcore and httpmime libraries. My build.gradle files dependancy section contains below part,

compile 'org.apache.httpcomponents:httpcore:4.4.4'
compile 'org.apache.httpcomponents:httpmime:4.5.2'

运行该应用程序时出现错误。日志如下所示,

and when I'm running the app gives an error. the log is as shown below,

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
 > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/NOTICE
        File1: /Users/marpak/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.5.2/22b4c53dd9b6761024258de8f9240c3dce6ea368/httpmime-4.5.2.jar
        File2: /Users/marpak/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.4/b31526a230871fbe285fbcbe2813f9c0839ae9b0/httpcore-4.4.4.jar

我该如何解决

推荐答案

将此问题添加到您的build.gradle文件中

add this in your build.gradle file

android {
    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'
    }
}

这篇关于将httpcore和httpmime库添加到Android项目会在运行该应用程序时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆