在打包期间Gradle重复文件--JodaTime的messages.properties

x-t*_*eme 8 android jodatime android-gradle-plugin

我换过JavaDate教学班JodaDateTime在我的Android应用程序最近的类.我Jackson用于解析json.我在build.gradle文件中添加了以下行

compile com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.3
compile net.danlew:android.joda:2.7.1
Run Code Online (Sandbox Code Playgroud)

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

android {
  packagingOptions {
    exclude 'org/joda/time/format/messages_da.properties'
  }
}
Run Code Online (Sandbox Code Playgroud)

在JodaTime中有很多这样的文件,如"messages_da.properties","messages_fr.properties".我相信这些用于提供基于区域设置的格式.

我的预感说不应该排除这些文件.如果那里的专家可以为此提供解决方案,那就太棒了

Sak*_*boy 6

这实际上是一个问题,取决于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'
    }
Run Code Online (Sandbox Code Playgroud)

通过这样做,你不必在这里依赖其他hacky答案.