Duplicate files copied in APK META-INF/license.txt

来源:互联网 发布:新闻联播配音软件 编辑:程序博客网 时间:2024/05/22 10:24

今天在尝试使用AndroidAnnotations框架的REST API时,在导入spring for Android包后仅编译的话不会报错,但是当运行时无法编译通过,并报一下错误:

[java] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. <span style="font-size:18px;">Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.  
  2. > com.android.build.api.transform.TransformException:   
  3.             com.android.builder.packaging.DuplicateFileException:   
  4.             Duplicate files copied in APK META-INF/license.txt  
  5.     File1: C:\Users\sea\.gradle\caches\modules-2\files-2.1\org.springframework.android  
  6.             \spring-android-rest-template\1.0.1.RELEASE\e132d929bd181941f79b0d63edafb8a86ae6fd33  
  7.             \spring-android-rest-template-1.0.1.RELEASE.jar  
  8.     File2: C:\Users\sea\.gradle\caches\modules-2\files-2.1\org.springframework.android  
  9.             \spring-android-core\1.0.1.RELEASE\e68f0e8e4b636ee30c4de58953be38d9b72a5e3b  
  10.             \spring-android-core-1.0.1.RELEASE.jar</span>  
解决办法是在Model的build.gradle中添加一下内容:

[java] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. android {  
  2.   
  3.     packagingOptions {  
  4.     exclude 'META-INF/LICENSE.txt'  
  5.     }  
  6.   
  7. }  
与之类似的,可以把完整的加进去

[java] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. android {  
  2.       
  3.   
  4.     packagingOptions {  
  5.         exclude 'META-INF/DEPENDENCIES.txt'  
  6.         exclude 'META-INF/LICENSE.txt'  
  7.         exclude 'META-INF/NOTICE.txt'  
  8.         exclude 'META-INF/NOTICE'  
  9.         exclude 'META-INF/LICENSE'  
  10.         exclude 'META-INF/DEPENDENCIES'  
  11.         exclude 'META-INF/notice.txt'  
  12.         exclude 'META-INF/license.txt'  
  13.         exclude 'META-INF/dependencies.txt'  
  14.         exclude 'META-INF/LGPL2.1'  
  15.     }  
  16. }  

按照stackoverflow上回答的问题原因是:

[python] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. Almost all OS licence include the obligation to "include a copy of the licence" into your project.   
  2. So this means, that you have to include a copy of all OS licences you use into you projects.   
  3. By "excluding" them in gradle, you violate the licences.  
0 0
原创粉丝点击