我在将 Jackson Parser 依赖项添加到我的项目时遇到问题。
目前我在我的 build.gradle 上使用这些代码行:
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
我唯一需要的类是 ObjectMapper,我知道它在数据绑定(bind)包中。当我在 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/NOTICE File1: C:\Users\Igor.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.7.2\84ffa765dd258dbab8695963c41308b054f3a1cb\jackson-databind-2.7.2.jar File2: C:\Users\Igor.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.7.2\8b8310381b690e317f5f0574e9b2dd7034778b4c\jackson-core-2.7.2.jar
我试着只留下数据绑定(bind)库,但我运气不好。同样的错误。
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
我尝试了 Build -> Clean Project
并删除了 .gradle/cache,但也没有成功。
我不知道这会是什么。有什么建议吗?
最佳答案
添加
android {
...
packagingOptions {
exclude 'META-INF/NOTICE' // It is not include NOTICE file
exclude 'META-INF/LICENSE' // It is not include LICENSE file
}
...
}
在你的 build.gradle
中。
关于Android Studio 无法在 gradle 上设置 Jackson Parser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909785/