Home » Android » android – Gradle duplicate files during packing – messages.properties of JodaTime

android – Gradle duplicate files during packing – messages.properties of JodaTime

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

How to&Answers:

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.

Answer:

I solved this issue like

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

Answer:

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