Reputation: 1015
I'm building a library and would like to use Volley for the networking aspects of it. I can either package the Volley jar and release the .aar, copy the source into my project and release a .jar (blah), or do some dependency magic with Gradle.
Either way I'm guessing I will have conflicts if any app trying to use my library also has a Volley dependency, either via .jar or gradle.
What is the correct way to do this?
I would prefer to not just require the user to remove their own dependencies on Volley to avoid the dexexception where multiple things define it, since that seems to be the most common solution to those errors.
Thanks
Upvotes: 2
Views: 1335
Reputation: 1106
Volley is a difficult one, since there aren't official artifacts published. Something you can do with your library project is to define Volley as a provided
dependency. This will compile your source against the Volley code, but won't package Volley code with your AAR. It would look like this:
dependencies {
//If you have source
provided project(':volley')
//If you have a jar
provided files('path/to/volley.jar')
}
This is not ideal since it will require people using your library to declare a Volley dependency. And since there is no official artifact, the version of Volley they have could be incompatible with what you compile against.
Upvotes: 1
Reputation:
If you get a conflict with a transitive dependency you could exclude it or don't define it on your project and use the one from the library project.
Gradle
dependencies {
compile("org.gradle.test.excludes:api:1.0") {
exclude module: 'shared'
}
}
Maven
<dependencies>
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Reference:
Gradle http://www.gradle.org/docs/current/userguide/dependency_management.html
Maven http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
Upvotes: 3