AlexAndro AlexAndro - 11 days ago 6
Android Question

Android Studio - Gradle dependencies - How to Exclude `bolts` from `facebook`?


Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.


com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
bolts/AggregateException.class



That's how the error looks like. I know that
bolts
is used in 3 of my dependencies,
com.facebook.fresco:fresco:0.10.0
,
com.parse:parse-android:1.13.1
and a jar
ePOS2.jar
.

I have tried multiple solutions, starting with

compile('com.facebook.fresco:fresco:0.10.0') {
exclude group: 'com.parse.bolts', module: 'bolts-android'
}


But I still get the error. I have also tried to exclude some parts from
com.parse:parse-android1.13.1
as shown in this post but then I get the missing classes error then.

I also enabled
multidex
as shown in this post but the error still occurs.

I tried to exclude
com/parse/bolts/AggregateException.class
as shown in this post, still the error occurs.

The strangest is that if I enable
InstantRun
I can run the app but crashes when it uses a certain class from the jar.


java.lang.UnsatisfiedLinkError:
com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader


So, I thought if is possible to exclude that certain class
AggregateException.class
either from jar or
com.parse:parse-android:1.13.1
?

EDIT


compile('com.facebook.fresco:fresco:0.10.0') {
exclude module: 'bolts-android'
}


OR


compile('com.facebook.fresco:fresco:0.10.0') {
exclude group: 'com.parse.bolts',
module: 'bolts-android'
}


I have tried to exclude
bolts
from
com.facebook.fresco:fresco:0.10.0
but whatever I do they still appear:

+--- com.android.support:multidex:1.0.1
+--- com.android.support:design:23.3.0
| +--- com.android.support:appcompat-v7:23.3.0
| | +--- com.android.support:support-vector-drawable:23.3.0
| | | \--- com.android.support:support-v4:23.3.0
| | | \--- com.android.support:support-annotations:23.3.0
| | +--- com.android.support:animated-vector-drawable:23.3.0
| | | \--- com.android.support:support-vector-drawable:23.3.0 (*)
| | \--- com.android.support:support-v4:23.3.0 (*)
| +--- com.android.support:support-v4:23.3.0 (*)
| \--- com.android.support:recyclerview-v7:23.3.0
| +--- com.android.support:support-v4:23.3.0 (*)
| \--- com.android.support:support-annotations:23.3.0
+--- com.makeramen:roundedimageview:2.2.1
+--- com.facebook.fresco:fresco:0.10.0
| +--- com.facebook.fresco:drawee:0.10.0
| | +--- com.android.support:support-v4:23.1.1 -> 23.3.0 (*)
| | \--- com.facebook.fresco:fbcore:0.10.0
| +--- com.facebook.fresco:fbcore:0.10.0
| \--- com.facebook.fresco:imagepipeline:0.10.0
| +--- com.android.support:support-v4:23.1.1 -> 23.3.0 (*)
| +--- com.nineoldandroids:library:2.4.0
| +--- com.facebook.fresco:fbcore:0.10.0
| +--- com.facebook.fresco:imagepipeline-base:0.10.0
| | +--- com.android.support:support-v4:23.1.1 -> 23.3.0 (*)
| | +--- com.nineoldandroids:library:2.4.0
| | +--- com.facebook.fresco:fbcore:0.10.0
| | \--- com.parse.bolts:bolts-android:1.1.4 !!! HERE
| \--- com.parse.bolts:bolts-android:1.1.4 !!! HERE
+--- com.facebook.fresco:imagepipeline-okhttp:0.7.0
| +--- com.squareup.okhttp:okhttp:2.3.0
| | \--- com.squareup.okio:okio:1.3.0
| +--- com.facebook.fresco:imagepipeline:0.7.0 -> 0.10.0 (*)
| \--- com.facebook.fresco:fbcore:0.7.0 -> 0.10.0
+--- com.parse:parse-android:1.13.1
| \--- com.parse.bolts:bolts-tasks:1.4.0
\--- uk.co.chrisjenx:calligraphy:2.2.0
\--- com.android.support:appcompat-v7:23.1.1 -> 23.3.0 (*)

Answer

The duplicate entry error ususally originates from the packager trying to package multiple different versions of the same class.

It seems that you've only excluded a specific part of the bolts library. This causes your build to mix 2 different version of the remaining parts of the library, which probably do still have some overlapping classes.

In my project I've excluded the whole library from every module, and then forced a unified bolts version to rule them all.

In my gradle build I've exluded bolts from all modules dependant on bolts, like this:

compile('com.facebook.android:facebook-android-sdk:4.14.1') {
    exclude group: 'com.parse.bolts'
}

And then forced all modules to use a the latest bolts:

compile 'com.parse.bolts:bolts-android:1.+'
Comments