Android, Gradle and duplicate files error during packaging

我与影子孤独终老i 提交于 2019-12-12 08:59:21

问题


I want to use the json-schema-validator in my Android project like this:

dependencies { compile 'com.github.fge:json-schema-validator:2.1.8' }

Unfortunately Gradle stops packaging due to this file duplicate error:

Path in archive: draftv3/schema Origin 1: /Users/andrej/.gradle/caches/modules-2/files-2.1/com.github.fge/json-schema-validator/2.1.8/4c2a5be8ce86c2338561a651d7d22fb4c4a8763d/json-schema-validator-2.1.8.jar Origin 2: /Users/andrej/.gradle/caches/modules-2/files-2.1/com.github.fge/json-schema-core/1.1.9/4ead9ba3fb3bde69d93f738042d12a9e60e41645/json-schema-core-1.1.9.jar

I know I can ignore the file like this:

packagingOptions { exclude 'draftv3/schema' }

But the file is used by json-schema-validator and json-validator-core, so it is required in the resulting APK.

How can I force Gradle to proceed packaging while keeping one of the two versions of this file (they are equal)?

Thanks, Andrej


回答1:


For others, here a quick workaround until Gradle will add packaging options with proper duplicate strategies:

android.applicationVariants.all { variant-> variant.assemble.doFirst { exec { executable "sh" args "-c", "find ~/.gradle/caches/ -iname 'json-schema-validator*.jar' -exec zip -d '{}' 'draftv3/schema' \\;" args "-c", "find ~/.gradle/caches/ -iname 'json-schema-validator*.jar' -exec zip -d '{}' 'draftv4/schema' \\;" } } }




回答2:


By explicitly mentioning the draftv/schema files in the build.graddle file we can resolve this issue.

    android {

    ...

        packagingOptions {

            ...

            pickFirst 'draftv3/schema'
            pickFirst 'draftv4/schema'

        }
    }



回答3:


Try the following to only exclude draftv3/schema from your dependency:

dependencies {
   compile('com.github.fge:json-schema-validator:2.1.8') {
       exclude 'draftv3/schema'
   }
}


来源:https://stackoverflow.com/questions/22228647/android-gradle-and-duplicate-files-error-during-packaging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!