ohadnav
(Ohad Navon)
August 2, 2017, 9:24pm
1
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?
Lance
(uklance)
August 3, 2017, 7:50pm
2
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"
}
}
}
ohadnav
(Ohad Navon)
August 3, 2017, 8:07pm
3
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
carlyonj
(Jordan Carlyon)
February 22, 2018, 5:19pm
4
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.
Lance
(uklance)
February 24, 2018, 6:02pm
5
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