macos-build
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuild macOS App
构建macOS应用
Build any native macOS Xcode project from the command line using .
xcodebuild使用从命令行构建任何原生macOS Xcode项目。
xcodebuildFinding the Project
查找项目
Before building, locate the Xcode project or workspace:
bash
find . -maxdepth 2 -name "*.xcodeproj" -o -name "*.xcworkspace" | head -5Then list available schemes:
bash
xcodebuild -list -project "YourApp.xcodeproj" 2>/dev/null | grep -A 20 "Schemes:"构建前,先定位Xcode项目或工作区:
bash
find . -maxdepth 2 -name "*.xcodeproj" -o -name "*.xcworkspace" | head -5然后列出可用的scheme:
bash
xcodebuild -list -project "YourApp.xcodeproj" 2>/dev/null | grep -A 20 "Schemes:"Build Command
构建命令
Use this command template, replacing the project path and scheme:
bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild build \
-project "YourApp.xcodeproj" \
-scheme "YourApp" \
-configuration Debug \
-destination "platform=macOS" \
2>&1 | grep -E "(BUILD SUCCEEDED|BUILD FAILED|error:)" | head -20For workspaces (projects with SPM dependencies or CocoaPods):
bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild build \
-workspace "YourApp.xcworkspace" \
-scheme "YourApp" \
-configuration Debug \
-destination "platform=macOS" \
2>&1 | grep -E "(BUILD SUCCEEDED|BUILD FAILED|error:)" | head -20使用以下命令模板,替换项目路径和scheme:
bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild build \
-project "YourApp.xcodeproj" \
-scheme "YourApp" \
-configuration Debug \
-destination "platform=macOS" \
2>&1 | grep -E "(BUILD SUCCEEDED|BUILD FAILED|error:)" | head -20对于包含SPM依赖或CocoaPods的工作区:
bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcodebuild build \
-workspace "YourApp.xcworkspace" \
-scheme "YourApp" \
-configuration Debug \
-destination "platform=macOS" \
2>&1 | grep -E "(BUILD SUCCEEDED|BUILD FAILED|error:)" | head -20Interpreting Results
结果解读
- BUILD SUCCEEDED -- the build passed, report success to the user.
- BUILD FAILED with lines -- read each error, identify the source file and line, and help the user fix them. After fixing, re-run the build to verify.
error: - If the output is empty or unclear, re-run without the grep filter to get full output for diagnosis.
- BUILD SUCCEEDED——构建通过,向用户报告成功。
- BUILD FAILED并带有行——读取每个错误,识别源文件和行号,帮助用户修复。修复后,重新运行构建以验证。
error: - 如果输出为空或不清晰,去掉grep过滤器重新运行以获取完整输出进行诊断。
When to Build
何时构建
- After making code changes, if the user asks to verify they compile
- When the user explicitly says "build", "compile", or "check if it builds"
- After fixing build errors, to confirm the fix worked
- 代码更改后,用户要求验证是否可编译时
- 用户明确说“构建”、“编译”或“检查是否可构建”时
- 修复构建错误后,确认修复生效时
Xcode Beta Toolchains
Xcode Beta工具链
If the project targets a beta SDK (e.g., macOS 26 Tahoe), you may need to point to the beta Xcode:
bash
DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild build ...Check which Xcode is available:
bash
ls /Applications/ | grep -i xcode如果项目针对Beta版SDK(例如macOS 26 Tahoe),可能需要指向Beta版Xcode:
bash
DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer xcodebuild build ...检查可用的Xcode:
bash
ls /Applications/ | grep -i xcodeCommon Build Failures
常见构建失败
| Error | Fix |
|---|---|
| SPM dependency not resolved. Try |
| Set |
| Wrong |
| Run |
| 错误 | 修复方法 |
|---|---|
| SPM依赖未解析。先尝试运行 |
| 为命令行构建设置 |
| |
| 运行 |