I use java.util.Base64.getEncoder() in Kotlin, but...
# android
h
I use java.util.Base64.getEncoder() in Kotlin, but on below of Nougat versions doesn't work. I get this error on below of Nougat versions "Failed resolution of: Ljava/util/Base64"
😶 2
m
Base64
was added in Java 8, so you can only use it on API versions that have Java 8. Android provides desugaring to get a lot of the Java 8 API usable on old devices, but I do not see
Base64
in that list. https://developer.android.com/studio/write/java8-support-table
💯 1
h
@mkrussel thanks for your reply. I added it, but no result
Copy code
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8.toString()
}
m
Those settings determine the byte code from Kotlin, and the syntax allowed by Java, but not the API that can be used. Those are part of the JVM that is installed on the device. So you can only use functionality introduced in Java 8 if it is in the list from the link above.
s
You could use
android.util.Base64
instead. That gets you back to Froyo.
👍 1
2