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

Xcodebuild命令执行成功但未生成Product产物问题求助

问题:xcodebuild命令行构建成功但无bundle产物生成

我使用Mac Sonoma 14.1.1系统与Xcode 15.0版本,尝试通过bash脚本执行xcodebuild命令构建bundle,命令如下:

sudo xcodebuild build -project $(dirname "$PWD")/MyProject.xcodeproj -scheme "INTEL_Generic" -derivedDataPath "derData/" -configuration Release HOME=${HOME}

使用sudo是为获取写入权限,设置HOME是因为脚本环境默认传递/var/root/而非/Users/me。虽然指定的derData目录生成了部分日志,但本该包含.bundle的build/Products文件夹缺失。通过Xcode界面执行Product->Build可正常生成产物,但命令行显示BUILD SUCCEEDED却无产物及中间文件生成,命令行输出如下:

Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild build -project /Users/me/Documents/MyProject.xcodeproj -scheme INTEL_Generic -derivedDataPath derData/ -configuration Release HOME=/Users/me

User defaults from command line:
IDEDerivedDataPathOverride = /Users/me/Documents/derData
IDEPackageSupportUseBuiltinSCM = YES

Build settings from command line:
HOME = /Users/me

--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:x86_64, id:13BCBEA6-9D69-52BE-9F0C-C03D51DA1439 }
{ platform:macOS, name:Any Mac }
ComputeTargetDependencyGraph
note: Building targets in dependency order
note: Target dependency graph (1 target)
Target 'INTEL_Project' in project 'Project' (no dependencies)

GatherProvisioningInputs

CreateBuildDescription

ClangStatCache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk /Users/me/Documents/derData/SDKStatCaches.noindex/macosx14.0-23A334-4a76ee93ef69e462914ffe9883de22b8.sdkstatcache
cd /Users/me/Documents/MyProject.xcodeproj
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -o /Users/me/derData/SDKStatCaches.noindex/macosx14.0-23A334-4a76ee93ef69e462914ffe9883de22b8.sdkstatcache

** BUILD SUCCEEDED **

解决方法

  • 明确指定构建目标的destination:命令行提示存在多个匹配目标,虽自动选择了第一个,但可能与Xcode界面使用的目标不一致。在命令中添加-destination 'platform=macOS,arch=x86_64',确保构建环境与界面完全匹配:
sudo xcodebuild build -project $(dirname "$PWD")/MyProject.xcodeproj -scheme "INTEL_Generic" -derivedDataPath "derData/" -configuration Release HOME=${HOME} -destination 'platform=macOS,arch=x86_64'
  • 修复sudo执行的目录权限:sudo运行时derData目录所有者可能变为root,导致后续无法完整写入产物。先手动创建目录并修改权限再执行命令:
mkdir -p derData
chown -R $(whoami):staff derData
sudo xcodebuild build -project $(dirname "$PWD")/MyProject.xcodeproj -scheme "INTEL_Generic" -derivedDataPath "derData/" -configuration Release HOME=${HOME}
  • 验证scheme的构建配置:打开Xcode检查INTEL_Generic scheme的Build配置,确认Release模式下是否勾选了对应的bundle目标。部分场景下命令行scheme配置可能与界面存在差异。

  • 查看详细构建日志:添加-verbose参数获取完整构建过程,排查是否有步骤跳过了产物生成:

sudo xcodebuild build -project $(dirname "$PWD")/MyProject.xcodeproj -scheme "INTEL_Generic" -derivedDataPath "derData/" -configuration Release HOME=${HOME} -verbose

内容的提问来源于stack exchange,提问作者copter

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 05:04:51