0

I´m building a simple app for android 4.4 and up, i have a method to decode base64 string using the apache-commons-codec library.

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

public static String decodeBase64(String toDecode) {
    byte[] decoded = Base64.decodeBase64(toDecode);

    return new String(decoded);
}

but when i call this static method from the main (like className.decodeBase64(VAR)) I receive the following error. error log

i'm currently using jdk 8 and the last version of android studio. I know that the jdk8 implements a base64 encoder/decoder but i can´t use it, because I was limited to programming to more recent android versions at 8.0

Oladipo
  • 1,579
  • 3
  • 17
  • 33
NormanP
  • 1
  • 2

2 Answers2

0

It may be an issue with the library version. Which version of commons-codec do you use in your build.gradle file? Try updating it to the latest, which is 1.13. Also this may be the solution for your issue: Apache Commons Codec with Android: could not find method

V. K.
  • 1
  • 2
  • Thanks for the response, i already try it. not working neither. the second option that i try was importing the jar file from Comms to the project. but dont work – NormanP Nov 06 '19 at 15:47
0

After two days looking for it, i find a nice solution.

Just need to replace the apache.commons with android.util.Base64, who'd say...

the method would look like the following:

import android.util.Base64;

public static String DecodeBase64(String toDecode){
    byte[] decodeValue = Base64.decode(toDecode, Base64.DEFAULT);
    return new String(decodeValue);
}

also, if someone knows how to solve the original error and please explain me why that happen, it would be helpful

NormanP
  • 1
  • 2