Apache Commons Codec with Android: could not find method Apache Commons Codec with Android: could not find method android android

Apache Commons Codec with Android: could not find method


I had a similar problem while using android with an OAuth library I'm developing.

I also got from android that, although I had included apache.commons.codec in the classpath, a particular method (encodeBase64String) was not found.

Checking the javadocs, both methods claim to be 1.4 and greater only, so my guess is that android already includes an older version of commons.codec where these methods are indeed undefined.

My solution was to use an older method, like this:

String encodedString = new String(Base64.encodeBase64('string to encode'));

The method you want to use is different since it replaces + and / with url-safe values - and _. So you probably might use something like:

String encodedString = new String(Base64.encodeBase64('string to encode'));String safeString = encodedString.replace('+','-').replace('/','_');

Hope that helps!


You don't have to use apache commons, on android you can use android.util.Base64 instead.


I experienced the exact same problem. So i started browsing the android source code, and as it turns out Pablo Fernandez's guess about Android having an implementation of org.apache.commons.code.binary is correct. However, its version 1.2 of the apache commons, not version 1.4 or even 1.5.You can see for your self in the android source.

as a note this is question is a duplicate of this post