将httpcore和httpmime库添加到Android项目会导致运行应用程序时出错

Sam*_*age 1 android http build.gradle

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

compile 'org.apache.httpcomponents:httpcore:4.4.4'
compile 'org.apache.httpcomponents:httpmime:4.5.2'
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序时出错.日志如下图所示,

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
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题

shi*_*lms 5

在build.gradle文件中添加它

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'
    }
}
Run Code Online (Sandbox Code Playgroud)