Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle duplicate files during packing - messages.properties of JodaTime

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

like image 428
x-treme Avatar asked Apr 10 '15 19:04

x-treme


2 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.

like image 108
Sakiboy Avatar answered Sep 22 '22 23:09

Sakiboy


I solved this issue like

android {
    packagingOptions {
        exclude 'org/joda/time/format/*.properties'
    }
}
like image 34
AsyncTask Avatar answered Sep 25 '22 23:09

AsyncTask