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

今天在尝试使用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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值