Thread
#multiplatform
    adjpd

    adjpd

    7 months ago
    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
    .
    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

    7 months ago
    java.time requires Java 8+, which is not satisfied on most Android versions
    adjpd

    adjpd

    7 months ago
    So I need to ensure i'm using java8?
    e

    ephemient

    7 months ago
    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
    (by "your code" I mean everything that gets built into the app, which includes kotlinx-datetime if you're using it as a dependency)
    adjpd

    adjpd

    7 months ago
    Thanks!
    compileOptions {
            isCoreLibraryDesugaringEnabled = true
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8
        }
    And
    dependencies {
        coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
    }
    Did it for me