Xcodebuild 命令行编译笔记
man Xcodebuild 获得帮助
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html
1. Xcodebuild -version 查看当前编译用的xcode的版本号和build版本
e.g.
Xcodebuild -version
Xcode 4.4.1
Build version 4F1003
2.显示当前系统的sdk及其版本
e.g.
xcodebuild -showsdks
OS X SDKs:
Mac OS X 10.7
-sdk macosx10.7
OS X 10.8
-sdk macosx10.8
iOS SDKs:
iOS 5.1
-sdk iphoneos5.1
iOS Simulator SDKs:
Simulator - iOS 5.1
-sdk iphonesimulator5.1
3.显示工程项目信息
先cd 到工程目录下(有*.xcodeproj的)xcodebuild -list
e.g.
xcodebuild -list
Information about project "lunboTest":
Targets:
lunboTest
Build Configurations:
Debug
Release
If no build configuration is specified and -scheme is not passed then "Release" is used.
Schemes:
lunboTest
如果未指定configuration, 默认为relese版本
4.xcodebuild 用法
1》xcodebuild -sdk iphonesimulator5.1
2》通过后面加上 -configuration Debug 编译为Degug版本
3》clean 工程 xcodebuild clean -sdk iphonesimulator5.1 -configuration Debug
XCODEBUILD(1) BSD General Commands Manual XCODEBUILD(1)
NAME
xcodebuild -- build Xcode projects and workspaces
SYNOPSIS
xcodebuild [-project projectname] [-target targetname ...] [-configuration configurationname]
[-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
[-userdefault=value ...]
xcodebuild [-project projectname] -scheme schemename [-configuration configurationname]
[-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
[-userdefault=value ...]
xcodebuild -workspace workspacename -scheme schemename [-configuration configurationname]
[-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
[-userdefault=value ...]
xcodebuild -version [-sdk [sdkfullpath | sdkname]] [infoitem]
xcodebuild -showsdks
xcodebuild -list [-project projectname | -workspace workspacename]
DESCRIPTION
xcodebuild builds one or more targets contained in an Xcode project, or builds a scheme contained in an
Xcode workspace or Xcode project.
Usage
To build an Xcode project, run xcodebuild from the directory containing your project (i.e. the
directory containing the projectname.xcodeproj package). If you have multiple projects in the this
directory you will need to use -project to indicate which project should be built. By default,
xcodebuild builds the first target listed in the project, with the default build configuration. The
order of the targets is a property of the project and is the same for all users of the project.
To build an Xcode workspace, you must pass both the -workspace and -scheme options to define the build.
The parameters of the scheme will control which targets are built and how they are built, although you
may pass other options to xcodebuild to override some parameters of the scheme.
There are also several parameters to display info about the installed version of Xcode or about
projects or workspaces in the local directory, but which do not initiate a build. These include
-version, -showsdks, and -usage.
Options
-project projectname
Build the project specified by projectname. Required if there are multiple project files in the
same directory.
-target targetname
Build the target specified by targetname.
-alltargets
Build all the targets in the specified project.
-workspace workspacename
Build the workspace specified by workspacename.
-scheme schemename
Build the scheme specified by schemename. Required if building a workspace.
-configuration configurationname
Use the build configuration specified by configurationname when building each target.
-arch architecture
Use the architecture specified by architecture when building each target.
-sdk [<sdkfullpath> | <sdkname>]
Build an Xcode project or workspace against the specified SDK, using build tools appropriate for
that SDK. The argument may be an absolute path to an SDK, or the canonical name of an SDK.
-showsdks
Lists all available SDKs that Xcode knows about, including their canonical names suitable for use
with -sdk. Does not initiate a build.
-list
Lists the targets and configurations in a project, or the schemes in a workspace. Does not initi-
ate a build.
buildaction ...
Specify a build action (or actions) to perform on the target. Available build actions are:
build Build the target in the build root (SYMROOT). This is the default build action.
archive Archive a scheme from the build root (SYMROOT). This requires specifying a scheme.
test Test a scheme from the build root (SYMROOT). This requires specifying a scheme.
installsrc Copy the source of the project to the source root (SRCROOT).
install Build the target and install it into the target's installation directory in the dis-
tribution root (DSTROOT).
clean Remove build products and intermediate files from the build root (SYMROOT).
-xcconfig filename
Load the build settings defined in filename when building all targets. These settings will over-
ride all other settings, including settings passed individually on the command line.
setting=value
Set the build setting setting to value.
-userdefault=value
Set the user default default to value.
-version
Display version information for this install of Xcode. Does not initiate a build. When used in
conjunction with -sdk, the version of the specified SDK is displayed, or all SDKs if -sdk is
given no argument. Additionally, a single line of the reported version information may be
returned if infoitem is specified.
-usage
Displays usage information for xcodebuild.
Environment Variables
The following environment variables affect the execution of xcodebuild:
XCODE_XCCONFIG_FILE
Set to a path to a file, build settings in that file will be loaded and used when
building all targets. These settings will override all other settings, including set-
tings passed individually on the command line, and those in the file passed with the
-xcconfig option.
Exit Codes
xcodebuild exits with codes defined by sysexits(3). It will exit with EX_OK on success. On failure,
it will commonly exit with EX_USAGE if any options appear malformed, EX_NOINPUT if any input files can-
not be found, EX_IOERR if any files cannot be read or written, and EX_SOFTWARE if the commands given to
xcodebuild fail. It may exit with other codes in less common scenarios.
EXAMPLES
xcodebuild clean install
Cleans the build directory; then builds and installs the first target in the Xcode project in
the directory from which xcodebuild was started.
xcodebuild -target MyTarget OBJROOT=/Build/MyProj/Obj.root SYMROOT=/Build/MyProj/Sym.root
Builds the target MyTarget in the Xcode project in the directory from which xcodebuild was
started, putting intermediate files in the directory /Build/MyProj/Obj.root and the products
of the build in the directory /Build/MyProj/Sym.root.
xcodebuild -sdk macosx10.6
Builds the Xcode project in the directory from which xcodebuild was started against the Mac OS
X 10.6 SDK. The canonical names of all available SDKs can be viewed using the -showsdks
option.
xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme
Builds the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace.
xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme archive
Archives the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace.
xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme test
Tests the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace.