【问题标题】:Gradle duplicate files during packing - messages.properties of JodaTime打包过程中的 Gradle 重复文件 - JodaTime 的 messages.properties
【发布时间】:2015-06-16 14:48:44
【问题描述】:

我最近在我的 Android 应用程序中将 JavaDate 类替换为 JodaDateTime 类。我使用Jackson 来解析json。我将以下行添加到我的 build.gradle 文件中

compile com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.3
compile net.danlew:android.joda:2.7.1

它破坏了我的构建。错误消息是duplicate files during packaging of APK。它还建议了以下选项

android {
  packagingOptions {
    exclude 'org/joda/time/format/messages_da.properties'
  }
}

在 JodaTime 中有很多这样的文件,例如“messages_da.properties”、“messages_fr.properties”。我相信这些用于提供基于语言环境的格式。

我的直觉是不应该排除这些文件。如果那里的专家可以为此提供解决方案,那就太好了

【问题讨论】:

  • 对于它的价值,你也可以使用 'pickFirst' 而不是 'exclude' 来使用它找到的第一个。
  • 在下面查看我的答案,它找到了问题的根源,解释了它,并展示了一个更好的解决方案。

标签: android android-gradle-plugin jodatime


【解决方案1】:

这实际上是依赖于项目中的多个 joda-time 模块导致的问题。

要解决此问题,您应该从项目中包含重复 joda-time 模块的任何依赖项中排除任何重复的 joda-time 模块。

要找出包含重复的joda-time 的依赖关系,请使用命令./gradlew app:dependencies 列出完整的依赖关系图。然后查看依赖项列表并找到包含重复的joda-time 模块的依赖项。然后将 joda-time 从包含其副本的任何依赖项中排除。完成此操作后,您的应用程序将构建良好。

如何从依赖项中排除 joda-time 的示例:

 // An offending dependency that contains a duplicate joda-time.
 compile('com.some.project:some-module:0.1') {
        // Exclude joda-time from this dependency to remove the errors.
        exclude module: 'joda-time'
    }

这是处理依赖冲突的正确方法。

【讨论】:

    【解决方案2】:

    我的肮脏解决方案:

    android {
        packagingOptions {
            exclude 'META-INF/maven/joda-time/joda-time/pom.properties'
            exclude 'META-INF/maven/joda-time/joda-time/pom.xml'
            pickFirst 'org/joda/time/format/messages.properties'
            pickFirst 'org/joda/time/format/messages_cs.properties'
            pickFirst 'org/joda/time/format/messages_da.properties'
            pickFirst 'org/joda/time/format/messages_de.properties'
            pickFirst 'org/joda/time/format/messages_en.properties'
            pickFirst 'org/joda/time/format/messages_es.properties'
            pickFirst 'org/joda/time/format/messages_fr.properties'
            pickFirst 'org/joda/time/format/messages_it.properties'
            pickFirst 'org/joda/time/format/messages_ja.properties'
            pickFirst 'org/joda/time/format/messages_no.properties'
            pickFirst 'org/joda/time/format/messages_nl.properties'
            pickFirst 'org/joda/time/format/messages_pl.properties'
            pickFirst 'org/joda/time/format/messages_pt.properties'
            pickFirst 'org/joda/time/format/messages_ru.properties'
            pickFirst 'org/joda/time/format/messages_tr.properties'
        }
    }
    

    【讨论】:

      【解决方案3】:

      我解决了这个问题

      android {
          packagingOptions {
              exclude 'org/joda/time/format/*.properties'
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-02-11
        • 2014-10-18
        • 1970-01-01
        • 2016-06-19
        • 2014-01-07
        • 1970-01-01
        相关资源
        最近更新 更多