在我的Android应用中,我使用的是httpcore和httpmime库。我的build.gradle文件依赖部分包含以下部分,
compile 'org.apache.httpcomponents:httpcore:4.4.4'
compile 'org.apache.httpcomponents:httpmime:4.5.2'
当我运行应用程序时出错。日志如下所示,
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
我该如何解决这个问题
答案 0 :(得分: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'
}
}
答案 1 :(得分:0)
最好使用这个,它只包含一个许可文件,一些许可(大多数开源)不允许从最终代码中排除许可:
${pageContext.response.getHeader('X-Foo-Bar')}
这不是最好的选择,因为如果你有不同的许可文件同名,你会丢失一个,但比排除一切要好得多。