I have a problem with Android libraries.
I would like use the method Hex.encodeHexString(Byte Array) from the library org.apache.commons.codec.binary.Hex (version 1.6)
On my Android platform (SDK 2.3.1), the commons-codec library version 1.3 already exist but the method doesn't exist yet in this version (only encodeHex() ).
I added the jar library of version 1.6 into my Eclipse project (into /libs directory) but when I run the project on Emulator, I get this :
E/AndroidRuntime(1632): FATAL EXCEPTION: main
E/AndroidRuntime(1632): java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Hex.encodeHexString
How can I indicate the OS where is the good library?
I'm using Eclipse Juno with Java 1.6.0 on Mac OS X
Sorry for my bad english and thanks in advance!
EDIT : My problem could be apparently solved with jarjar tool. http://code.google.com/p/google-http-java-client/issues/detail?id=75
Someone could help me with this tool? I don't know how to create an Ant Manifest or a jar file.
Thanks
This is due to a namespace collision resulting from and old (1.2) version of Commons Codec that comes packaged with Android colliding with your newer version. While shading is a good workaround, I don't think it is a sustainable solution in the long run. This is a systemic problem that can arise with any open source library that is packaged in Android. I've submitted an issue to Google. If you agree, I encourage you to "star" it so that it gets the attention it needs. Here's the link - https://code.google.com/p/android/issues/detail?id=160578
Regarding nbe_42's maven shade plugin, where the plugin block is put in the pom.xml file is very important or maven will miss it.
What worked for me was to put it at the end of the
<build> <plugins>
block in pom.xml:Originally I had it at the start of the block and maven did not run it.
To create the .jar file download the commons-codec-1.8-src.zip source .zip archive from apache.org. Unpack it. The pom.xml file will be in the base directory of the archive. Insert nbe_42's plugin block in the pom.xml file as described above and run:
This will build, test, replace and install the plugin for you.
Output on success should look something like this:
Have you added the library to the build path of the project? When you've done that you should be able to call the method from the jar file.
If it builds OK without adding the library then you may be building against a newer version of android then effectively deploying to an older one, I found out the hard way that
String.isEmpty()
isn't in 2.1 but when I was writing the code it build OK as I was building against 4.1You may need to export the jar with your project (again you can do this as you configure the build path).
Hope this helps
Late reply but maybe usefull for someone.
Problem solved by using Maven Shade Plugin
This plugin allows to rename package names of conflicted library at compilation.
Usage :
Expanded version of nbe_42's answer, with full documentation...
The commons-codec-shaded jar project:
And in the (apk/apklib/aar/jar) project(s) where you want to use the shaded library: