【问题标题】:Android, Gradle and duplicate files error during packagingAndroid、Gradle 和打包过程中的重复文件错误
【发布时间】:2014-03-06 15:20:41
【问题描述】:

我想在我的 Android 项目中使用 json-schema-validator,如下所示:

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

很遗憾,由于此文件重复错误,Gradle 停止打包:

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

我知道我可以像这样忽略文件:

packagingOptions { exclude 'draftv3/schema' }

但该文件被 json-schema-validator 和 json-validator-core 使用,因此在生成的 APK 中是必需的。

如何强制 Gradle 继续打包,同时保留此文件的两个版本之一(它们相等)?

谢谢, 安德烈

【问题讨论】:

    标签: android gradle android-studio jsonschema


    【解决方案1】:

    对于其他人,这里有一个快速的解决方法,直到 Gradle 使用适当的重复策略添加打包选项:

    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】:

      通过在 build.graddle 文件中明确提及 Draftv/schema 文件,我们可以解决此问题。

          android {
      
          ...
      
              packagingOptions {
      
                  ...
      
                  pickFirst 'draftv3/schema'
                  pickFirst 'draftv4/schema'
      
              }
          }
      

      【讨论】:

        【解决方案3】:

        尝试以下操作以仅从您的依赖项中排除 draftv3/schema

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

        【讨论】:

        • 这会将文件排除在打包之外。但该文件被 json-schema-validator 和 json-validator-core 使用,因此在生成的 APK 中是必需的。
        • 你是如何添加 json-validator-core 依赖的?
        • json-validator-core 由 "dependencies { compile 'com.github.fge:json-schema-validator:2.1.8' }" 自动添加
        猜你喜欢
        • 2015-08-02
        • 2015-06-16
        • 2016-06-19
        • 1970-01-01
        • 2014-01-07
        • 2015-12-11
        • 1970-01-01
        • 2015-12-20
        相关资源
        最近更新 更多