← 返回命令列表

Linux command

xcodebuild 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Build a project

xcodebuild

Build a specific scheme

xcodebuild -scheme [SchemeName]

Build for a specific SDK

xcodebuild -scheme [SchemeName] -sdk iphoneos -destination "generic/platform=iOS"

Build a workspace

xcodebuild -workspace [App.xcworkspace] -scheme [SchemeName]

Create an archive

xcodebuild archive -scheme [SchemeName] -archivePath [path/to/App.xcarchive]

Export an archive

xcodebuild -exportArchive -archivePath [App.xcarchive] -exportPath [output] -exportOptionsPlist [options.plist]

Run tests

xcodebuild test -scheme [SchemeName] -destination "platform=iOS Simulator,name=iPhone 15"

List available schemes

xcodebuild -list

List available SDKs

xcodebuild -showsdks

说明

xcodebuild is Apple's command-line tool for building Xcode projects and workspaces. It performs build, test, archive, and export operations, making it essential for CI/CD pipelines and automated builds of macOS, iOS, watchOS, and tvOS applications. The tool works with projects (.xcodeproj) or workspaces (.xcworkspace). Workspaces, commonly used with CocoaPods or Swift Package Manager, require specifying a scheme. Schemes define which targets to build and with what configuration. Building for iOS distribution is typically a two-step process: first archive to create an .xcarchive, then -exportArchive with an export options plist to produce the final .ipa file. Code signing and provisioning can be managed automatically with -allowProvisioningUpdates.

参数

-project _name_
Build the project specified by name.xcodeproj.
-workspace _name_
Build the workspace specified by name.xcworkspace.
-scheme _name_
Build the scheme with the specified name. Required for workspaces.
-target _name_
Build the target with the specified name.
-sdk _sdk_
Build with the specified SDK (iphoneos, iphonesimulator, macosx).
-destination _destination_
Use the destination described by destination.
-configuration _config_
Build configuration: Debug or Release.
-archivePath _path_
Path for archive output.
-exportPath _path_
Path for export output.
-exportOptionsPlist _path_
Plist file specifying export options.
-list
List all targets, schemes, and configurations.
-showsdks
List all available SDKs.
-allowProvisioningUpdates
Allow automatic provisioning profile management.
build
Build the target (default action).
archive
Create an archive for distribution.
test
Run unit tests.
clean
Remove build products.

FAQ

What is the xcodebuild command used for?

xcodebuild is Apple's command-line tool for building Xcode projects and workspaces. It performs build, test, archive, and export operations, making it essential for CI/CD pipelines and automated builds of macOS, iOS, watchOS, and tvOS applications. The tool works with projects (.xcodeproj) or workspaces (.xcworkspace). Workspaces, commonly used with CocoaPods or Swift Package Manager, require specifying a scheme. Schemes define which targets to build and with what configuration. Building for iOS distribution is typically a two-step process: first archive to create an .xcarchive, then -exportArchive with an export options plist to produce the final .ipa file. Code signing and provisioning can be managed automatically with -allowProvisioningUpdates.

How do I run a basic xcodebuild example?

Run `xcodebuild` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -project _name_ do in xcodebuild?

Build the project specified by name.xcodeproj.