今天在尝试使用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.