项目中添加了两个jar包 ,编译时出现如下错误:
Error:Execution failed for task ':social_sdk_library_project:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE.txt
File1: /Users/zhujiaming/Desktop/pro_as_yzy/social_sdk_library_project/libs/twitter4j-core-4.0.4.jar
File2: /Users/zhujiaming/Desktop/pro_as_yzy/social_sdk_library_project/libs/httpmime-4.1.3.jar
网络求助之后得到较为专业的回答:
看起来是因为多个 jar 包里包含了同样的文件(NOTICE.txt),导致打包时因为担心相互覆盖问题而提示出错。
尝试下在 app 下的 build.gradle 中的 android 部分增加一段配置:
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
添加之后,错误消失了,估计就是这个原因。