9

I replaced Java's Date classes with Joda's DateTime classes recently in my Android app. I use Jackson for parsing json. I added the following lines to my build.gradle file

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

It broke my build. The error message is duplicate files during packaging of APK. It also suggested the following option

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

There are many such files like that in JodaTime like "messages_da.properties", "messages_fr.properties". I believe those are used to provide locale based formatting.

My hunch says that these files should not be excluded. If experts out there can provide a solution for this, it would be great

x-treme
  • 1,606
  • 2
  • 21
  • 39

3 Answers3

14

This is actually an issue that results from depending on multiple joda-time modules in your project.

To fix this, you should exclude any duplicate joda-time module(s) from any dependency in your project that contains a duplicate joda-time module.

To find out what dependencies are including the duplicate joda-time, use the command ./gradlew app:dependencies to list your complete dependency graph. Then look through the list of dependencies and find the ones that includes the duplicate joda-time module. Then exclude joda-time from any dependency that includes a duplicate of it. After doing this your app will build fine.

Example of how to exclude joda-time from a dependency:

 // 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'
    }

This is the correct way to handle dependency conflicts.

Sakiboy
  • 7,252
  • 7
  • 52
  • 69
4

I solved this issue like

android {
    packagingOptions {
        exclude 'org/joda/time/format/*.properties'
    }
}
AsyncTask
  • 419
  • 1
  • 7
  • 24
3

My dirty solution:

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'
    }
}
Sakiboy
  • 7,252
  • 7
  • 52
  • 69
Alexandr
  • 3,859
  • 5
  • 32
  • 56