Search code examples
androiddagger-2gradle-shadow-plugin

Getting duplicate entries exception when adding shadow generated jars in my project


I am using the shadow plugin for Gradle to generate modified jars for Dagger 2. The jar files are generated as expected, but when I add the jars as dependencies to my proyect i get

Error:Execution failed for task ':transformClassesAndResourcesWithSyncLibJarsForRelease'.
> java.util.zip.ZipException: duplicate entry: META-INF/maven/com.google.dagger/dagger/pom.properties

To give toy the context of my case: I have an app with the next structure

CoreLib

|

Lib1

|

App

CoreLib and Lib1 uses these jar files generated by shadow to replace dagger2. But when running the app I get the previous exception in Lib1.

I add the jars like this in both libraries

 apt files('libs/two-daggers-compiler-1.0.0.jar')
compile files('libs/two-daggers-library-1.0.0.jar')

Any ideas??


Solution

  • The solution for my problem was that I had to exclude the duplicated files.

    I added this to my application buid.gradle and the problem was solved.

    packagingOptions {
        exclude 'META-INF/maven/com.google.dagger/dagger/pom.xml'
        exclude 'META-INF/maven/com.google.dagger/dagger/pom.properties'
    }
    

    I added it in the android block