Hi there – I’m running into an unusual error link...
# serialization
b
Hi there – I’m running into an unusual error linking against an Apple (iOS) framework built from a Kotlin MPP project after adding a dependency to
kotlinx-serialization-json
. The project: – contains
androidMain
,
commonMain
, and
iosMain
sourceSets – built to a framework using the
syncFramework
task created by applying the Cocoapods plugin, and run using a pod post_install hook – already uses
kotlinx-serialization-protobuf
across all source sets already without incident Our Kotlin language version is 1.5.21. The serialization plugin is applied in this manner:
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    kotlin("plugin.serialization") version "1.5.21"
And the dependency on kotlinx-serialization-protobuf is defined in this manner:
Copy code
val commonMain by getting {
            dependsOn(designSystemMain)
            dependencies {
                ...
                implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
                ...
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.2.1")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
            }
        }
A serializable class is defined like so:
Copy code
@ExperimentalSerializationApi
@Serializable
data class AuthorizerRequestInfo(
    @SerialName("token")
    val token: String,
    @SerialName("client-id")
    val clientId: String,
)
Source in iosMain attempts encodes an instance of the data class in this manner:
Copy code
Json.encodeToString(
    serializer = serializer(),
    value = AuthorizerRequestInfo(
        token = ...,
        clientId = ...
    )
)
The iOS framework is successfully built using the
syncFramework
command, but a linker issue occurs when statically linking the framework into the application:
Copy code
Showing All Messages
Ld [redacted]/[redacted].app/[redacted] normal (in target '[redacted]' from project '[redacted]')
    cd 
    ....
Undefined symbols for architecture x86_64:
  "_kfun:kotlinx.serialization.json.JsonClassDiscriminator#<get-discriminator>(){}kotlin.String", referenced from:
      _kfun:kotlinx.serialization.json.internal#classDiscriminator__at__kotlinx.serialization.descriptors.SerialDescriptor(kotlinx.serialization.json.Json){}kotlin.String in [redacted](result.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
We aren’t making use of class discriminator, note how ‘simple’ the
AuthorizerRequestInfo
class in question is, so I’m left kind of stumped. Interestingly, the tasks that compile our
iosTest
source set & links our unit test target for iOS completes successfully – we can spawn a simulator and run a test executable with them, without incident. Does anyone have guidance on how we can debug this further?
(Following up for posterity) Filed https://youtrack.jetbrains.com/issue/KT-49888