I imported commons-codec-1.10.jar by following these steps:
- The libs directory is created in the application directory
- Manually copied .jar to the libs directory
- Right click on .jar inside android studio and click "Add as library"
Added this line to my build.grade
compile fileTree(dir: 'libs', include: ['*.jar'])
In my class, I imported the library as follows:
import org.apache.commons.codec.binary.Base64;
Then I tried to access the encodeBase64String static method inside Base64 as follows:
public static class DoThisThing {
public String DoThisOtherThing() {
String hashed = "hello";
String hash = Base64.encodeBase64String(hashed.getBytes());
return hash;
}
}
public class ActivityThing extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_thing);
String hash = DoThisThing.DoThisOtherThing();
System.out.println(hash);
}
}
There is nothing bad there, even when I compile, except when I launch the application, it gives the following error and the application shuts down:
11-03 09:41:27.719 2390-2476/com.myproject E/AndroidRuntime: Caused by: java.lang.NoSuchMethodError: No static method encodeBase64String([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
DoThisThing, , , . , , encodeBase64String . , , java android.