Mysterious duplicate zip entry

Using Dagger 2.+ conflicts with another dependency that uses of Dagger 1.+, and the following error occurs when running gradle build

Warning: Exception while processing task java.io.IOException: Can’t write […] (Can’t read […/com.squareup.dagger/dagger/1.2.2/…/dagger-1.2.2.jar(;;;;;;**.class)] (Duplicate zip entry [dagger-1.2.2.jar:dagger/Lazy.class]))

Use this build.gradle to reproduce (in Android Studio):

android {
  compileSdkVersion 26
  buildToolsVersion "26.0.0"
  defaultConfig {
    applicationId "com.example.myapplication4"
    minSdkVersion 21
    targetSdkVersion 26
    multiDexEnabled true
  }
  buildTypes {
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}
dependencies {
  compile fileTree(include: ["*.jar"], dir: "libs")
  compile "com.android.support:appcompat-v7:26.+"
  compile "com.google.dagger:dagger:2.+"
  compile "com.affectiva.android:affdexsdk:3.+"
}

Strangely enough the following does not lead to the error:

dependencies {
  compile fileTree(include: ["*.jar"], dir: "libs")
  compile "com.android.support:appcompat-v7:26.+"
  compile "com.google.dagger:dagger:2.+"
  compile "com.squareup.dagger:dagger:1.2.2"
}

Any idea how can I investigate further?

Run this task

task findDuplicates() {
   doLast {
      Map grouped = [:] 
      configurations.compile.each { jarFile ->
         zipTree(jarFile).visit { FileVisitDetails fvd -> {
            def path = fvd.relativePath.path
            def matches = grouped[path]?:[] 
            matches << jarFile
            grouped[path] = matches
         } 
      } 
      grouped.each { path, matches ->
         if (matches.size() > 1) println "found $path in $matches" 
      } 
   } 
} 

There is no access for com.affectiva.android:affdexsdk:3.+
The result is:

A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
   > Could not resolve com.affectiva.android:affdexsdk:3.+.
     Required by:
         project :app
      > Could not resolve com.affectiva.android:affdexsdk:3.+.
         > Failed to list versions for com.affectiva.android:affdexsdk.
            > Unable to load Maven meta-data from http://maven.affectiva.com/com/affectiva/android/affdexsdk/maven-metadata.xml.
               > Could not GET 'http://maven.affectiva.com/com/affectiva/android/affdexsdk/maven-metadata.xml'.
                  > maven.affectiva.com

That is not a valid task, it is not properly formatted.

    task findDuplicates() {
    doLast {
        Map grouped = [:]
        configurations.compile.each { jarFile ->
            zipTree(jarFile).visit { FileVisitDetails fvd ->
                def path = fvd.relativePath.path
                def matches = grouped[path] ?: []
                matches << jarFile
                grouped[path] = matches
            }
        }
        grouped.each { path, matches ->
            if (matches.size() > 1) println "found $path in $matches"
        }
    }
}

I removed an extra open bracket, this will run but I don’t think it does anything.

It won’t actually fix anything, it will print out any classes which are duplicated (appear in more than one jar) which will help resolve the problem