Question

My Android library requires some of the newer Apache HTTPClient jar files so that I can upload a multipart file (See related SO question)

I'm pretty sure there will be some apps out there using my library with a different version of these Apache JAR files already, resulting in a conflict.

I've seen this happen quite a few times with android-support-v4.jar and third-party libraries. Is there any best-practice work-around, or should I implement multipart uploading from scratch?

Was it helpful?

Solution

You can repackage the apache http client so that it uses a new package name so that it does not conflict with any other versions on the classpath.

This question explains how to do it with the maven shade plugin,

This article explains how to do it with jarjar and ant.

OTHER TIPS

Another option is httpclientandroidlib. Basically the author created a script to change the package name (so it doesn't conflict with the Android version) and remove some functionality (due to dependencies on org.ietf.jgss).

Script can be found here.

I would say that best practice would be building your library as a Maven project with dependencies. Most libraries today are provided that way and it also lets you automatically generate jars with dependencies either included or not.

See for instance dagger-compiler at http://search.maven.org/#search%7Cga%7C1%7Cdagger-compiler which has both a jar without dependencies included and a jar-with-dependencies

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top