Gradle "Duplicate Class" Error When Adding UCrop And Cometchat Libraries
When I add the UCrop library version 2.2.3 and Cometchat SDK version 1.6.+ I get the following error :
Duplicate class okhttp3.Address found in modules okhttp-3.11.0.jar (com.squareup.okhttp3:okhttp:3.11.0) and okhttp-3.12.0.jar (com.cometchat:pro-android-chat-sdk:1.6.0)
The problem is that none of the previously asked questions have answers that solved my problem because most of them use the 'compile' method which is now deprecated.
I read many questions here on stackoverflow about the same topic, including this , this.
I've also tried excluding okhttp3 library from one of the packages so that only one is used , using
implementation('com.github.yalantis:ucrop:2.2.3' )
{
exclude group: 'com.cometchat', module: 'okhttp3'
}
I would appreciate it if someone could explain to me how excludes work in gradle and what's wrong with the code that I wrote.
Answer
Instead of excluding okhttp3
from com.cometchat
group try doing this
implementation('com.cometchat:pro-android-chat-sdk:1.6.0') {
configurations {
compile.exclude module: 'okhttp'
}
}
The conflict is due to your both UCrop
and CometChat
dependencies internally uses okhttp
library.To resolve this problem you have to exclude conflicting library.
Excluding transitive dependency can be done two different ways.
- Exclude transitive dependency by configuration
- Exclude transitive dependency by dependency
To read more about gradle dependency
conflict cause and solution you can check out this link
https://www.concretepage.com/build-tools/gradle/gradle-exclude-transitive-dependency-example
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View