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.