You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

KMM iOS编译报Incompatible abi version错误如何解决?

核心错误原因

编译失败的根本原因是Kotlin版本与Ktor依赖版本不兼容:你项目全局使用的Kotlin编译器版本是1.5.10,但引入的Ktor 1.6.3版本是用Kotlin 1.5.20编译的,两者Native ABI版本不匹配,导致iOS编译时无法识别Ktor的iOS原生库。
你之前只修改iOS端Ktor依赖版本的操作无效,是因为所有端的Ktor依赖必须统一版本,包括公共模块、Android模块、iOS模块的Ktor相关依赖。

可行解决方案

方案1:对齐Ktor版本到与Kotlin 1.5.10兼容的版本

将所有模块中所有Ktor相关依赖的版本统一改为1.6.2,该版本Ktor完全适配Kotlin 1.5.10:

  1. 修改shared模块build.gradle.kts中的依赖:
    // commonMain里的依赖
    implementation("io.ktor:ktor-client-core:1.6.2")
    implementation("io.ktor:ktor-client-serialization:1.6.2")
    // androidMain里的依赖
    implementation("io.ktor:ktor-client-android:1.6.2")
    // iosMain里的依赖
    implementation("io.ktor:ktor-client-ios:1.6.2")
    

方案2:升级全局Kotlin版本到匹配Ktor 1.6.3的版本

如果要保留Ktor 1.6.3版本,就把根目录build.gradle.kts里的Kotlin插件版本升级到1.5.20:

// 根目录build.gradle.kts的dependencies块
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20")
// 同时把shared模块里的serialization插件版本也改成1.5.20
kotlin("plugin.serialization") version "1.5.20"

配套操作(必做,避免缓存干扰)

版本修改完成后执行以下操作清理所有缓存:

  • 执行./gradlew clean清理项目本地构建产物
  • 执行./gradlew --stop停止所有运行中的Gradle守护进程
  • 进入iOS项目目录,执行pod deintegrate && pod install重新安装CocoaPods依赖
  • 打开Xcode,按Command + Shift + K清理Xcode构建缓存,再重新编译

可选:消除测试源集警告

日志中开头的源集警告不会直接导致编译失败,若要消除可以在shared模块的sourceSets块中添加如下配置:

val androidAndroidTestRelease by getting {
    dependsOn(androidTest.get())
}
val androidTestFixtures by getting
val androidTestFixturesDebug by getting {
    dependsOn(androidTestFixtures)
}
val androidTestFixturesRelease by getting {
    dependsOn(androidTestFixtures)
}

内容的提问来源于stack exchange,提问作者Jérémie Guillot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 00:15:03