環境: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文件夾。
QQ截圖20170218184147.png
將這個目錄下的子文件名添,按步驟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.