KMM项目从Android Studio部署至iOS模拟器时构建失败求助
KMM项目iOS模拟器构建失败(适配新版IDE)
问题场景
- 环境:Android Studio Jellyfish、Xcode 15.3、iOS模拟器17.4,所有插件及依赖已更新至最新
- 现象:仅iOS模拟器部署时出现构建失败,Android模拟器运行正常
- 已知旧版IDE解决方案无效
错误日志
The following build commands failed: PhaseScriptExecution Compile\ Kotlin\Framework/Users/xblack/KMPprojects/KMPdemo2/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Script-F36B1CEB2AD83DDC00CB74D5.sh (in target 'iosApp' from project 'iosApp') (1 failure) warning: Run script build phase 'Compile Kotlin Framework' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'iosApp' from project 'iosApp')
适配新版IDE的解决办法
1. 补全脚本阶段的输出依赖(推荐)
这是解决警告及构建失败的根本方案:
- 打开iOS工程的
.xcodeproj/.xcworkspace,选中iosApptarget - 切换到Build Phases标签,找到
Compile Kotlin Framework脚本块 - 点击脚本右侧的
+,添加对应架构的框架输出路径(替换成你的KMM框架名称):- Debug x86_64模拟器:
$(SRCROOT)/../build/ios/x86_64-simulator/debug/frameworks/你的框架名.framework - Debug arm64模拟器:
$(SRCROOT)/../build/ios/arm64-simulator/debug/frameworks/你的框架名.framework - 需适配Release环境时,同理添加对应release路径
- Debug x86_64模拟器:
- 确认勾选
Based on dependency analysis,重新构建项目
2. 关闭依赖分析(临时快速修复)
若不想配置输出路径,可强制脚本每次运行:
- 进入Xcode的
iosApptarget -> Build Phases ->Compile Kotlin Framework - 取消勾选
Based on dependency analysis - 执行
Cmd+Shift+K清理缓存后重新构建
3. 检查KMM插件与架构配置
- 打开项目根目录的
build.gradle.kts,确保Kotlin Multiplatform插件为适配Android Studio Jellyfish的最新稳定版(如2.0.0+) - 确认iOS目标架构包含模拟器所需的x86_64和arm64:
kotlin { iosSimulatorArm64 { binaries.framework { baseName = "你的框架名" } } iosX64 { binaries.framework { baseName = "你的框架名" } } // 其他iOS目标配置... }
- 同步项目后回到Xcode重新构建
4. 彻底清理缓存
若以上方案无效,尝试清理所有构建缓存:
- Android Studio:
File -> Invalidate Caches... -> Invalidate and Restart - Xcode:
Product -> Clean Build Folder,再删除对应项目的DerivedData(Xcode设置->Locations->DerivedData) - 删除项目根目录的
build文件夹和iOS工程的build文件夹 - 重启IDE后重新构建
内容的提问来源于stack exchange,提问作者X-Black
相关产品推荐
相关产品推荐

