Reputation: 129
I've tried this library on plain Kotlin, it's working well. But when I've tried on Android, it doesn't work anymore. Why? What is the difference between codes that I wrote on Kotlin and Android/Kotlin? What is the connection between an API and Java library?
Error on Logcat:
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/LocalTime;
The line I got error is:
val current = LocalTime.now().hour
Upvotes: 0
Views: 191
Reputation: 844
I've tried this library on plain Kotlin, it's working well. But when I've tried on Android, it doesn't work anymore. Why?
Java 8 introduced new Date and time classes (and a lot of other utiility classes), previously developers mostly used Joda Time a third party library as the built-in java date classes where not reliable and limited in functionality. By default the java and kotlin compilers targets java 6 which is max supported upto android 25 (Nougat).
What is the connection between an API and Java library?
An api is built into the target device and alibrary has to be shipped with your app.
What is the difference between codes that I wrote on Kotlin and Android/Kotlin
There is not much difference between the java and kotlin compiler, only the target jvm's. Though the kotlin compiler will usually compile code that will fail to run later as it heavily relies on annotations (which you setup)
Depending on your environment (target 6 or 8 for kotlin and java) and your devices (android version 25 and below or above 26) the code will have different classes available to it and setting the target jvm will allow consistancy across android versions.
Upvotes: 1