Commons CodecのBase64クラス使うとCould not find methodが発生する
API Version 4(Android OS 1.6)ではBase64エンコード/デコードするクラスが用意されていないので、Apache CommonsのCommons Codecを使ったところ、見事にハマったのでまとめときます。
現象
Commons CodecにあるBase64クラスを使ったコードをシミュレータ(Android OS 1.6)で実行すると、次のようなエラーが発生する。
ERROR/dalvikvm(574): Could not find method org.apache.commons.codec.binary.Base64.decodeBase64, referenced from method jp.xxxxxx.xxxxxx.xxxxxx
原因
「android commons Could not find method」でググるといろいろと出てきますが、
な辺りが起因してるのか、と。
I copied the java source code of Base64 to my project into the the namespace of org.apache.commons.codec.binary. The project compiled without any problem. However, at the runtime in Android simulator, I had the same error, java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String.However, after I changed the namespace to com.apache.commons.codec.binary instead of org, the app runs like magic. I guess inside Android implementation, org.apache.commons.codec.binary is used and it doesn't allow you to use it in your code again.