0

I am new to Android Development and I am using Android Studio 0.8.9 with Gradle Version 1.12. I want to use the Commons Codec Library, specifically the Base64 class to call the method

 encodeBase64URLSafe

I have download the latest commons-codec-1.9.jar file, added it to the created "libs" folder in Android Studio and then within build.gradle, I added the following:

dependencies {
compile 'com.android.support:support-v4:+'
compile files('libs/commons-codec-1.9.jar')
compile files('libs/guava-18.0.jar')
}

When I run my code, the app crashes and I get the following error message:

java.lang.NoSuchMethodError: Lorg/apache/commons/codec/binary/Base64;.encodeBase64URLSafe

I have no idea what is going on. I believe it has something to do with Android Studio not knowing the path of the commons-code jar library I added. However, it compiles without any issues.

If anyone can provide any insight, it would truly be appreciated.

Thanks!

Teddy13
  • 3,824
  • 11
  • 42
  • 69
  • Check out this SO thread: http://stackoverflow.com/questions/2047706/apache-commons-codec-with-android-could-not-find-method – alpinescrambler Sep 19 '14 at 21:38
  • @alpinescrambler It didn't help me solve my problem, it suggested a work around. I need this method. Thanks anyway! – Teddy13 Sep 20 '14 at 03:47

1 Answers1

0

Base64#encodeBase64URLSafe method was added in version 1.4 of Commons Code library. The Android runtime will always use version 1.3 of this class, which doesn't include this method - thus the NoSuchMethodError exception.

The solution for this will be to repackage the Commons Codec library.
Check out my answer here that includes steps to resolve this issue.

Community
  • 1
  • 1
Alex Lipov
  • 13,503
  • 5
  • 64
  • 87