'Xcode fails to build KMM project due to shared:linkPodDebugFrameworkIos

I am building a small project with KMM, it builds perfectly fine on android but cannot build it in XCode. Cocoapods was also installed an genereted without any erros.

What I'm using:

  • macbook air m1
  • Kotlin 1.6.10,
  • gradle 7.3.0-alpha03
  • Ktor 1.5.2,
  • SQLDelight 1.4.3,

You can find the project here: https://github.com/PiotrKedra/comperative-analysis-of-kmm-flutter-react-native/tree/master/preapp-kmm

The error I got:

...

> Task :shared:linkPodDebugFrameworkIos FAILED
e: Compilation failed: Backend Internal error: Exception during IR lowering
File being compiled: /opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/commonMain/src/kotlinx/serialization/json/internal/TreeJsonDecoder.kt
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.ir.util.IrFakeOverrideUtilsKt.getTarget(IrFakeOverrideUtils.kt:24)

* Source files: 
* Compiler version info: Konan: 1.6.10 / Kotlin: 1.6.10
* Output kind: FRAMEWORK

e: org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: /opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/commonMain/src/kotlinx/serialization/json/internal/TreeJsonDecoder.kt
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.ir.util.IrFakeOverrideUtilsKt.getTarget(IrFakeOverrideUtils.kt:24)

...

Caused by: java.lang.IllegalStateException: Could not resolveFakeOverride() for FUN FAKE_OVERRIDE name:decodeNullableSerializableElement visibility:public modality:OPEN <T> ($this:kotlinx.serialization.encoding.CompositeDecoder, descriptor:kotlinx.serialization.descriptors.SerialDescriptor, i:kotlin.Int, deserializer:kotlinx.serialization.DeserializationStrategy<T of kotlinx.serialization.json.internal.AbstractJsonTreeDecoder.decodeNullableSerializableElement?>) returnType:T of kotlinx.serialization.json.internal.AbstractJsonTreeDecoder.decodeNullableSerializableElement? [fake_override]
at org.jetbrains.kotlin.ir.util.IrFakeOverrideUtilsKt.getTarget(IrFakeOverrideUtils.kt:24)

...


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:linkPodDebugFrameworkIos'.
> Compilation finished with errors


Solution 1:[1]

For Kotlin 1.6.10, you need Ktor that was build on Kotlin 1.6.10. Ktor 1.6.8 is what you need. You will also need to inclode Kotlinx.serialization into the common module. Currently, you only have the plugin for Ktor (I'm guessing you are trying to deserialize network calls directly into appropriate data classes).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Webfreak