Kotlin/Native 构建 iOS 应用程序时 compileKotlinIosX64 任务失败

Kotlin/Native compileKotlinIosX64 task fails when building iOS app

我有一个 Kotlin Multiplatform 项目。我最近更新到 Kotlin 1.4-M2(我需要它来解决 Ktor 的一些问题)。 在更新所有必需的库、解决所有 gradle 问题并成功编译我的 Android 项目后,我现在在构建 iOS 应用程序时遇到以下错误:

Task :shared:compileKotlinIosX64
e: Compilation failed: Could not find declaration for unbound symbol org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl@56f11f08
* Source files: [all shared folder kt files]
 * Compiler version info: Konan: 1.4-M2 / Kotlin: 1.4.0
 * Output kind: LIBRARY
e: java.lang.IllegalStateException: Could not find declaration for unbound symbol org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl@56f11f08
    at org.jetbrains.kotlin.ir.util.ExternalDependenciesGeneratorKt.getDeclaration(ExternalDependenciesGenerator.kt:76)

奇怪的是,在源文件中它显示了共享代码文件夹中的所有文件。我检查了一下,绝对所有 kt 文件都出现在那里。所以我的猜测是在构建共享代码时出现了一些问题,但似乎并不特定于任何库。

这是我的 build.gradle.kts 的略微缩小版本:

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("kotlinx-serialization")
    id("com.android.library")
    id("io.fabric")
}

// CocoaPods requires the podspec to have a version.
version = "1.0"

tasks {
    withType<KotlinCompile> {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
}

kotlin {
    ios()
    android()

cocoapods {
    // Configure fields required by CocoaPods.
    summary = "Some description for a Kotlin/Native module"
    homepage = "Link to a Kotlin/Native module homepage"
}

sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializationVersion")
                api("org.kodein.di:kodein-di:7.1.0-kotlin-1.4-M3-84")
                implementation("io.mockk:mockk:1.9.2")

                api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")

                api("com.russhwolf:multiplatform-settings:$multiplatformSettingsVersion")

                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-json:$ktorVersion")
                implementation("io.ktor:ktor-client-logging:$ktorVersion")
                implementation("io.ktor:ktor-client-serialization:$ktorVersion")
            }
        }
}
}

库版本如下:

val ktorVersion = "1.3.2-1.4-M2"
val kotlinVersion = "1.4-M2"
val coroutinesVersion = "1.3.7-native-mt-1.4-M2"
val serializationVersion = "0.20.0-1.4-M2"
val multiplatformSettingsVersion = "0.6-1.4-M2"

值得一提的是,使用 1.3.72 时 iOS 可以正确构建。

按照@KevinGalligan 的建议,我将 Kotlin 和所有相关库更新到 1.4.0-rc,问题就解决了。

1.4-M2 的根本问题仍然未知。