Kotlin / kotlinx-datetime

KotlinX multiplatform date/time library
Apache License 2.0
2.37k stars 97 forks source link

Invalid record (Producer: 'LLVM8.0.0svn' Reader: 'LLVM APPLE_1_1200.0.32.21_0') #63

Closed sweiss435 closed 3 years ago

sweiss435 commented 3 years ago

I have it integrated correctly in my Kotlin Multiplatform project, and it will work fine for my android app. However, when I go to build my IOS app, I get this failure to build. Had hoped this was related to the apple developer tools and that the recent Xcode update would fix it, but problem persists.

I can change nothing else, even have import kotlinx.datetime.LocalDateTime in files, and both my android and iOS apps will run. As soon as I add a LocalDateTime field to a model, the android app will still work, but my iOS app won't compile.

Seems like a native Kotlin date time lib is essential, not sure why this is so new. I saw a commit a while back for an IOS crash fix, and think this is likely due to older compiler tools used when the last tag was made. When do we get a 0.1.1? Is this project still active or is there something else we can be using?

ilya-g commented 3 years ago

I saw a commit a while back for an IOS crash fix

I don't think that commit will help you. It fixed a runtime crash, and this looks like a compile time error.

Could you describe your build environment in more detail? Which tool produces this error?

sweiss435 commented 3 years ago

Gradle 6.7, kotlin 1.4.10, android build gradle tools 4.1.1. upgraded to datetime:0.1.1, plugins Multiplatform, kapt, kotlinx-serialization, com.squareup.sqldelight, com.android.library, and kotlin-android-extensions Yes, it is a compile time error. I thought I made that clear. If I remove a var in my model that uses kotlinx.datetime.LocalDateTime, things work fine, compiles to both android and iOS.
var looks like
@SerialName("creationDate") @Serializable(with = LocalDateTimeSerializer::class) @Contextual val creationDate: LocalDateTime,

I mean I can keep the imports and it compiles fine, maybe you guys break on compiling a localdatetimeserializer annotation that simply looks like: @ExperimentalSerializationApi @Serializer(forClass = LocalDateTime::class) class LocalDateTimeSerializer(override val descriptor: SerialDescriptor) : KSerializer { override fun serialize(encoder: Encoder, value: LocalDateTime) { encoder.encodeString(value.toString()) } override fun deserialize(decoder: Decoder): LocalDateTime { return LocalDateTime.parse(decoder.decodeString()) } } which clearly uses an experimental api

sweiss435 commented 3 years ago

I created a brand new super basic KMM app from the Android studio wizard. Did just like I said, created a model with a LocalDateTime field. Added some pretty standard dependencies I want to use, or that were otherwise working fine until I tried to use LocalDateTime in Kotlinx-datetime. https://github.com/sweiss435/datetimebuildfailure I can't imagine I'm the only one having this issue, it seems like all roads led me strait to this configuration and it seems like this is the main reason you'd need this library for when building a KMM app.

dkhalanskyjb commented 3 years ago

Thank you for the reproducer. Your code fails to build for me as well. I will look into it.

dkhalanskyjb commented 3 years ago

It seems that the problem was with the incorrect implementation of a serializer. I made this commit: https://github.com/dkhalanskyjb/datetimebuildfailure/commit/cf4955fe87195702bd5201c087508dfc967600ae After that, the build works fine for me. Could you please check if this fixes the issue for you, too?

sweiss435 commented 3 years ago

Works great. Bizarre it compiled and worked in the android app. I thought I had scoured the internet looking for examples on a serializer when I made this a while back.

dkhalanskyjb commented 3 years ago

This is good news. Also, an authoritative resource on writing custom serializers can be found here: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md