9

I am developing an Android Library. The Library is having few dependency. I am not sure what will happen if the developer use my library with other dependencies already present in my Library. I tried to googling about this but couldn't find anything.

For example I am using Volley Library of version X in my Library and shipping it as gradle package. And the developer imports Volley with Version Y along with my Library.

What should be the best way to include a Dependency in a Library (module, jar or package) so as to minimise conflict situation.

Abhishek Batra
  • 1,539
  • 1
  • 18
  • 45
  • 1
    Would be nice if there were documentation that answers this question. As it is, we're left with SO as our best avenue to answer this question. While it's not specific, it _is_ something that all android programmers will have to deal with eventually. And a general answer would be more helpful than a thousand specific ones. – SMBiggs Mar 14 '17 at 03:57

2 Answers2

1

Two options

  1. Possible ways to include the dependencies of your dependencies in them is to create a fat/uber/share jar (there are Gradle plugins for that). Use a custom classloader to load jars within a jar using One-Jar. Or to use Jar Jar Links.
  2. The second option is to specificaly exclude transistive dependencies doing:

    compile('X') {
        exclude module: 'Y'
    }
    
HELOX
  • 529
  • 2
  • 13
0

You will specify the user to exlude the other libs. Example from my gradle

compile('com.mobprofs:retrofit-simplexmlconverter:1.1') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
}

In general the user if will have conflicts and he will know how gradle works he will be able to add the eclude libs

Raluca Lucaci
  • 2,058
  • 3
  • 20
  • 37
  • These module will be excluded from the imported Library ? Or the user project? – Abhishek Batra Jun 12 '15 at 07:55
  • https://docs.gradle.org/current/userguide/dependency_management.html -> go to 50.4.7. Excluding transitive dependencies – Raluca Lucaci Jun 12 '15 at 07:58
  • had you take a look here http://stackoverflow.com/questions/16601299/how-to-create-a-library-project-in-android-studio-and-an-application-project-tha and here http://stackoverflow.com/questions/16718026/how-to-build-an-android-library-with-android-studio-and-gradle ? – Raluca Lucaci Jun 12 '15 at 08:02