2

Actually, I am developing an Android Application with encryption. When I use the Base64 for encoding and decoding, I receive an error of

Java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String() 

at run-time.

I know there are some posts on Stackflow which has been discussed the main cause of the problem ==> there are different versions of commons-codec.

Could anybody describe how to solve this problem in details? (So far, I know two solutions are workable).

1) Import the org.apache.commons.codec.binary.Base64 as client named package.;
2) Update the default lib of commons-codec)

Currently, I am using adt-bundle-windows-x86-20131030 for developing my application. Here is some of the coding for reference.

import org.apache.commons.codec.binary.Base64;

public static String receiveSetup(String messageFromActivity)
        throws Exception {
    SecretKey tempKey2 = DES.loadKey();
    byte[] test2 = Base64.decodeBase64(messageFromActivity);
    byte[] printString = DES.decrypt(test2, tempKey2);
    String str = new String(printString, "UTF-8");
    return str;
}
super-qua
  • 3,087
  • 1
  • 21
  • 28
Justin Yum
  • 133
  • 1
  • 1
  • 5

2 Answers2

1

Base64#encodeBase64String method was added in version 1.4 of Commons Codec library.

The thing is that the Android framework includes this class, and the runtime will use its version (and not the class that you packaged inside your app). Since framework shipped with version 1.3 of Commons Codec, the requested method is not present.

Check out my answer here that includes steps to resolve this issue.

Community
  • 1
  • 1
Alex Lipov
  • 11,917
  • 4
  • 58
  • 80
0

have u aware about sun.misc.BASE64Decoder jar file just include this jar file in your project dude name is sun.misc.BASE64Decoder

Bhanu Sharma
  • 4,946
  • 1
  • 21
  • 46