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 DEX files define error which means that there are duplications.

However, If I remove my library from the project, I cannot use its provided methods. And I cannot find how can I remove that library from the module.

Any suggestions?


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:

define multiDexEnable True in your build.gradle(app)

defaultConfig {

    multiDexEnabled true

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

    compile ''

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.


 ? Using lookup list in Teradata (Using Teradata SQL Assistant)
 ? ode using events to input external variable into equations
 ? external anchor link doesn't work in Chrome
 ? Unresolved external symbol in singleton
 ? Can't call inline javascript function from external scripts
 ? How to apply style to HTML subdocuments?
 ? JavaFX children edit without external css files
 ? How to Open External URL in Browser and Internal URL in Webview
 ? build.sbt ProjectRef : not enough arguments for method apply
 ? Angular2 2.4 How to load external libraries sush as Underscore into angular2.