Apologies, I've scanned the many similar-sounding questions and none of them have helped me.
I'm running Android Studio 3.0.1, I'm a newbie, I'm following the online tutorial "HelloWorld" program but then adding a call to java.util.Base64.getDecoder(). This fails at runtime when I run it on my actual phone (Samsung Galaxy S8):
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/util/Base64;
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.util.Base64" on path: DexPathList[[zip file "/data/app/com.skedgo.helloworld-1/base.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.skedgo.helloworld-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.skedgo.helloworld-1/lib/arm64, /system/lib64, /vendor/lib64]]
I have in AndroidManifest.xml:
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27"/>
I have: Compile SDK Version: API 26: Android 8.0 (Oreo)
How can I solve this problem?
I was under the belief that "java.util.Base64" was part of the standard Java library, at least for the version I'm using, so I shouldn't need to do anything special to use it. I don't know anything about Gradle but I know that I'm using it.
replace java.util.Base64
with android.util.Base64
. android doesn't use openjdk or oracle jre so the standard packages may not be there.
Just replace
import java.util.Base64;
with
import android.util.Base64;
And then modify your code to something like this (just an example):
String encoded = Base64.encode(someString.getBytes(), Base64.DEFAULT)); // for encoding
String decoded = Base64.decode(encoded, Base64.DEFAULT)); // for decoding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With