https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

adjpd

02/10/2022, 11:24 PM
When I start a new KMM project, add
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
to
commonMain
in my
shared
module, add
Clock.System.now().epochSeconds
in my
Greeting
file, then run the application in Android, it crashes with an error about not finding
java.time.Instance
.
1
Copy code
Process: com.example.mykmm.android, PID: 2988
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Instant;
 	at kotlinx.datetime.Instant.<clinit>(Instant.kt:94)
 	at kotlinx.datetime.Clock$System.now(Clock.kt:14)
 	at com.example.mykmm.Greeting.greeting(Greeting.kt:7)
And it does not crash on iOS... 🤷‍♂️
e

ephemient

02/10/2022, 11:31 PM
java.time requires Java 8+, which is not satisfied on most Android versions
a

adjpd

02/10/2022, 11:31 PM
So I need to ensure i'm using java8?
e

ephemient

02/10/2022, 11:32 PM
Android just doesn't have Java 8 (at least, not exactly)
see https://developer.android.com/studio/write/java8-support-table for how to enable desugaring where the build system rewrites a subset of Java 8 APIs into something that works on older devices
🙌 1
(by "your code" I mean everything that gets built into the app, which includes kotlinx-datetime if you're using it as a dependency)
a

adjpd

02/10/2022, 11:40 PM
Thanks!
Copy code
compileOptions {
        isCoreLibraryDesugaringEnabled = true
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
And
Copy code
dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
}
👍 1
Did it for me
8 Views