1

I'm experiencing this exception on a simple app in Android api 19 using commons-codec-1.9. Seems that Android use an old commons-codec library but I can't figure out because.

I'm usign Android studio and my gradle file contains this:

dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

The exception I have:

java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decode           
        at com.SplashActivity.onCreate(SplashActivity.java:32)
        at android.app.Activity.performCreate(Activity.java:5241)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248)
        at android.app.ActivityThread.access$800(ActivityThread.java:138)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5050)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
        at dalvik.system.NativeStart.main(Native Method)

Thanks

drenda
  • 5,846
  • 11
  • 68
  • 141
  • It's an old question, but Google brought me here before I found the answer. While not detailed in the documentation, Android apparently includes older versions of at least some of the Apache Commons libraries, and those take precedence. I never saw a definitive answer to if you can override them, but I solved the issue in my case by refactoring the package names and using those. – tstaylor7 Nov 02 '14 at 06:00

1 Answers1

-1

Instead of using the Apache Commons Base64 codec you should use the one provided by android.util.Base64

LJ in NJ
  • 196
  • 1
  • 1
  • 12
  • From a unit testing perspect, the Android Base64 class requires usages to be tested under instrumentation testing. From a re-usability standpoint, java libs should work everywhere and Android shading over dependencies is a legitimate issue. Simply switching Base64 implementations is not always an answer. – ian.shaun.thomas Oct 13 '17 at 15:44