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

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

<span style="font-size:18px;">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.txt
	File1: C:\Users\sea\.gradle\caches\modules-2\files-2.1\org.springframework.android
            \spring-android-rest-template\1.0.1.RELEASE\e132d929bd181941f79b0d63edafb8a86ae6fd33
            \spring-android-rest-template-1.0.1.RELEASE.jar
	File2: C:\Users\sea\.gradle\caches\modules-2\files-2.1\org.springframework.android
            \spring-android-core\1.0.1.RELEASE\e68f0e8e4b636ee30c4de58953be38d9b72a5e3b
            \spring-android-core-1.0.1.RELEASE.jar</span>
解决办法是在Model的build.gradle中添加一下内容:

android {

    packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    }

}
与之类似的,可以把完整的加进去

android {
    

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}

按照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.




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值