环境:gradle+Android studio
问题:运行工程时报如下错误信息,
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/LICENSE
File1: D:\Program Files\apache-maven\repo\org\codehaus\jackson\jackson-mapper-asl\1.9.7\jackson-mapper-asl-1.9.7.jar
File2: D:\Program Files\apache-maven\repo\org\codehaus\jackson\jackson-core-asl\1.9.7\jackson-core-asl-1.9.7.jar
解决方法:
1、找到相应的.jar文件,用WinRAR(解压工具)打开。打开META-INF文件夹。
将这个目录下的子文件名添,按步骤2进行添加。
2、在Model的build.gradle中添加一下内容:
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/ASL2.0'
}
按照stackoverflow上回答的问题原因是:
Almost all OS licence include the obligation to "include a copy of the licence" into your project.
So this means, that you have to include a copy of all OS licences you use into you projects.
By "excluding" them in gradle, you violate the licences.