Skip to content Skip to sidebar Skip to footer

How To Use Only One Library (are Multiple Same Ones)

Situation is that I in my project use library A. I also import external library which also has itself a library A. So as you can assume, when I try to compile, I receive Multiple D

Solution 1:

You should be able to exclude it like this:

compile('library:1.0.0') {
exclude group: 'something', module: 'something'
}

So do this on the external library for all the things you're using that's causing a problem.

From here: https://discuss.gradle.org/t/how-to-exclude-transitive-dependency/2119/2


Solution 2:

define multiDexEnable True in your build.gradle(app)

defaultConfig {

    multiDexEnabled true
 }

and also define in dependency in same build.gradle(app)

    compile 'com.android.support:multidex:1.0.1'

Solution 3:

Thank you guys for your suggestions. I didn't want to do as Michael suggested because I believe it is kind of useless (having multiple libraries with same purpose) (already knew this trick). I have tried Ядм Жцмдшдт answer, but couldn't succeed in compiling code completely. I have received various errors.

In the end I have solved my own issue. What I did:

Remove library from my main app libs folder. Remove dependancies if any in Android Studio (File -> Project Structure -> Dependencies (On module app) -> remove if any regarding your library. Clean project in Android Studio (Build -> Clean Project). Go to the module where my library A is. Go to that module build.gradle file and add following line in the dependencies cluster

compile files('libs/libraryA.jar')

Sync code and enjoy results.

TLDR I didn't have libraryA compiled in my external module but it threw me duplication error, that's where I was confused. By removing it from my main project and adding it to my module's compilations list solved the problem.


Post a Comment for "How To Use Only One Library (are Multiple Same Ones)"