xcodebuild命令详解

1.NAME

xcodebuild -- build Xcode projects and workspaces

2.SYNOPSIS


xcodebuild [-project name.xcodeproj] [[-target targetname] ... | -alltargets] [-configuration configurationname] [-sdk [sdkfullpath | sdkname]] [action ...]
[buildsetting=value ...] [-userdefault=value ...]


xcodebuild [-project name.xcodeproj] -scheme schemename [[-destination destinationspecifier] ...] [-destination-timeout value] [-configuration configurationname]
[-sdk [sdkfullpath | sdkname]] [action ...] [buildsetting=value ...] [-userdefault=value ...]


xcodebuild -workspace name.xcworkspace -scheme schemename [[-destination destinationspecifier] ...] [-destination-timeout value] [-configuration configurationname]
[-sdk [sdkfullpath | sdkname]] [action ...] [buildsetting=value ...] [-userdefault=value ...]


xcodebuild -version [-sdk [sdkfullpath | sdkname]] [infoitem]


xcodebuild -showsdks


xcodebuild -showBuildSettings [-project name.xcodeproj | [-workspace name.xcworkspace -scheme schemename]]


xcodebuild -list [-project name.xcodeproj | -workspace name.xcworkspace]


xcodebuild -exportArchive -archivePath xcarchivepath -exportPath destinationpath -exportOptionsPlist path


xcodebuild -exportLocalizations -project name.xcodeproj -localizationPath path [[-exportLanguage language] ...]


xcodebuild -importLocalizations -project name.xcodeproj -localizationPath path

4.action ...

       Specify one or more actions to perform. Available actions are:

       build                  Build the target in the build root (SYMROOT).  This is the default action, and is used if no action is given.

       build-for-testing      Build the target and associated tests in the build root (SYMROOT).  This will also produce an xctestrun file in the build root. This requires spec-
                              ifying a scheme.

       analyze                Build and analyze a target or scheme from the build root (SYMROOT).  This requires specifying a scheme.

       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 and optionally a destination.

       test-without-building  Test compiled bundles. If a scheme is provided with **-scheme** then the command finds bundles in the build root (SRCROOT).  If an xctestrun file is
                              provided with **-xctestrun** then the command finds bundles at paths specified in the xctestrun file.

       install-src            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 distribution root (DSTROOT).

       clean                  Remove build products and intermediate files from the build root (SYMROOT).

3.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 name.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 options that display info about the installed version of Xcode or about projects or workspaces in the local directory, but which do not initiate an
action. These include -list, -showBuildSettings, -showsdks, -usage, and -version.


Options
-project name.xcodeproj
Build the project name.xcodeproj. 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 name.xcworkspace
Build the workspace name.xcworkspace.
-scheme schemename
Build the scheme specified by schemename. Required if building a workspace.
-destination destinationspecifier
Use the destination device described by destinationspecifier. Defaults to a destination that is compatible with the selected scheme. See the Destinations section below
for more details.
-destination-timeout timeout
Use the specified timeout when searching for a destination device. The default is 30 seconds.
-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 canoni-
cal 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.
-showBuildSettings
Lists the build settings in a project or workspace and scheme. Does not initiate a build. Use with -project or -workspace and -scheme.
-list
Lists the targets and configurations in a project, or the schemes in a workspace. Does not initiate a build. Use with -project or -workspace.
-enableAddressSanitizer [YES | NO]
Turns the address sanitizer on or off. This overrides the setting for the launch action of a scheme in a workspace.
-enableThreadSanitizer [YES | NO]
Turns the thread sanitizer on or off. This overrides the setting for the launch action of a scheme in a workspace.
-enableCodeCoverage [YES | NO]
Turns code coverage on or off during testing. This overrides the setting for the test action of a scheme in a workspace.
-derivedDataPath path
Overrides the folder that should be used for derived data when performing an action on a scheme in a workspace.
-resultBundlePath path
Writes a bundle to the specified path with results from performing an action on a scheme in a workspace.
-exportArchive
Specifies that an archive should be exported. Requires -archivePath, -exportPath, and -exportOptionsPlist. Cannot be passed along with an action.
-archivePath xcarchivepath
Specifies the path for the archive produced by the archive action, or specifies the archive that should be exported when -exportArchive is passed.
-exportPath destinationpath
Specifies the destination for the exported product, including the name of the exported file.
-exportOptionsPlist path
Specifies options for -exportArchive. xcodebuild -help can print the full set of available options.
-exportLocalizations
Exports localizations to XLIFF files. Requires -project and -localizationPath. Cannot be passed along with an action.
-importLocalizations
Imports localizations from an XLIFF file. Requires -project and -localizationPath. Cannot be passed along with an action.
-localizationPath
Specifies a path to a directory or a single XLIFF localization file.
-exportLanguage language
Specifies optional ISO 639-1 languages included in a localization export. May be repeated to specify multiple languages. May be excluded to specify an export includes only development language strings.

4.action:Specify one or more actions to perform. Available actions

build
Build the target in the build root (SYMROOT). This is the default action, and is used if no action is given.
build-for-testing
Build the target and associated tests in the build root (SYMROOT). This will also produce an xctestrun file in the build root. This requires spec-
ifying a scheme.
analyze
Build and analyze a target or scheme from the build root (SYMROOT). This requires specifying a scheme.
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 and optionally a destination.
test-without-building
Test compiled bundles. If a scheme is provided with -scheme then the command finds bundles in the build root (SRCROOT). If an xctestrun file is
provided with -xctestrun then the command finds bundles at paths specified in the xctestrun file.
install-src
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 distribution 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 override all other settings, including settings passed individually on the
command line.


-xctestrun xctestrunpath
Specifies test run parameters. Can only be used with the test-without-building action. Cannot be used with -workspace or -project. See <x-man-page://5/
xcodebuild.xctestrun> for file format details.


-skip-testing:test-identifier, -only-testing:test-identifier
Constrain test actions. -only-testing: constrains a test action to only testing a specified identifier, and excluding all other identifiers. -skip-testing: constrains a
test action to skip testing a specified identifier, but including all other identifiers. Test identifiers have the form TestTarget[/TestClass[/TestMethod]]. An xcodebuild
command can combine multiple constraint options, but -only-testing: has precedence over -skip-testing:.


-dry-run, -n
Print the commands that would be executed, but do not execute them.


-skipUnavailableActions
Skip actions that cannot be performed instead of failing. This option is only honored if -scheme is passed.


buildsetting=value
Set the build setting buildsetting to value.
A detailed reference of Xcode build settings can be found at: https://developer.apple.com/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/


-userdefault=value
Set the user default userdefault to value.


-toolchain [identifier | name]
Use a given toolchain, specified with either an identifier or name.


-quiet
Do not print any output except for warnings and errors.


-verbose
Provide additional status output.


-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.


-license
Show the Xcode and SDK license agreements. Allows for accepting the license agreements without launching Xcode itself, which is useful for headless systems. Must be run
as a privileged user.


-usage
Displays usage information for xcodebuild.


5.Destinations

The -destination option takes as its argument a destination specifier describing the device (or devices) to use as a destination. A destination specifier is a single argument
consisting of a set of comma-separated key=value pairs. The -destination option may be specified multiple times to cause xcodebuild to perform the specified action on multiple
destinations.
Destination specifiers may include the platform key to specify one of the supported destination platforms. There are additional keys which should be supplied depending on the
platform of the device you are selecting.
Some devices may take time to look up. The -destination-timeout option can be used to specify the amount of time to wait before a device is considered unavailable. If unspeci-
fied, the default timeout is 30 seconds.

 Currently, **xcodebuild** supports these platforms:

 macOS              The local Mac, referred to in the Xcode interface as My Mac, and which supports the following key:

                    arch  The architecture to use, either x86_64 (the default) or i386.

 iOS                An iOS device, which supports the following keys:

                    id    The identifier of the device to use, as shown in the Devices window. A valid destination specifier must provide either id or name, but not both.

                    name  The name of the device to use. A valid destination specifier must provide either id or name, but not both.

 iOS Simulator      A simulated iOS device, which supports the following keys:

                    id    The  identifier  of  the simulated device to use, as shown in the Devices window. A valid destination specifier must provide either id or name, but not
                          both.

                    name  The name of the simulated device to use. A valid destination specifier must provide either id or name, but not both.

                    OS    When specifying the simulated device by name, the iOS version for that simulated device, such as 6.0, or the string latest (the  default)  to  indicate
                          the most recent version of iOS supported by this version of Xcode.

 watchOS            A  watchOS app is always built and deployed nested inside of an iOS app. To use a watchOS device as your destination, specify a scheme which is configured to
                    run a WatchKit app, and specify the iOS platform destination that is paired with the watchOS device you want to use.

 watchOS Simulator  A watchOS Simulator app is always built and deployed nested inside of an iOS Simulator app. To use a watchOS Simulator device as your destination, specify  a
                    scheme  which  is  configured  to run a WatchKit app, and specify the iOS Simulator platform destination that is paired with the watchOS Simulator device you
                    want to use.

 tvOS               A tvOS device, which supports the following keys:

                    id    The identifier of the device to use, as shown in the Devices window. A valid destination specifier must provide either id or name, but not both.

                    name  The name of the device to use. A valid destination specifier must provide either id or name, but not both.

 tvOS Simulator     A simulated tvOS device, which supports the following keys:

                    id    The identifier of the simulated device to use, as shown in the Devices window. A valid destination specifier must provide either id or  name,  but  not
                          both.

                    name  The name of the simulated device to use. A valid destination specifier must provide either id or name, but not both.

                    OS    When  specifying  the simulated device by name, the tvOS version for that simulated device, such as 9.0, or the string latest (the default) to indicate
                          the most recent version of tvOS supported by this version of Xcode.

Some actions (such as building) may be performed without an actual device present. To build against a platform generically instead of a specific device, the destination speci-
fier may be prefixed with the optional string "generic/", indicating that the platform should be targeted generically. An example of a generic destination is the "Generic iOS
Device" destination displayed in Xcode's UI when no physical iOS device is present.
Exporting Archives
The -exportArchive option specifies that xcodebuild should export the archive specified by -archivePath using the options specified by -exportOptionsPlist. xcodebuild -help
can print the full set of available inputs to -exportOptionsPlist. The exported product will be placed at the path specified by -exportPath.

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 settings 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 cannot 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.


6.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 -project MyProject.xcodeproj -target Target1 -target Target2 -configuration Debug

          Builds the targets Target1 and Target2 in the project MyProject.xcodeproj using the Debug configuration.

 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 macOS 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 archive -workspace MyWorkspace.xcworkspace -scheme MyScheme

          Archives the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace.

 xcodebuild build-for-testing -workspace MyWorkspace.xcworkspace -scheme MyScheme -destination generic/platform=iOS

          Build tests and associated targets in the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace using the generic iOS device destination. The command also
          writes test parameters from the scheme to an xctestrun file in the built products directory.

 xcodebuild test-without-building -workspace MyWorkspace.xcworkspace -scheme MyScheme -destination 'platform=iOS Simulator,name=iPhone 5s' -destination 'platform=iOS,name=My
          iPad'

          Tests the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace using both the iOS Simulator and the device named iPhone 5s for the latest version of iOS. The
          command assumes the test bundles are in the build root (SYMROOT).  (Note that the shell requires arguments to be quoted or otherwise escaped if they contain spaces.)

 xcodebuild test-without-building -xctestrun MyTestRun.xctestrun -destination 'platform=iOS Simulator,name=iPhone 5s' -destination 'platform=iOS,name=My iPad'

          Tests using both the iOS Simulator and the device named iPhone 5s.  Test bundle paths and other test parameters are specified in MyTestRun.xctestrun.  The command
          requires project binaries and does not require project source code.

 xcodebuild test -workspace MyWorkspace.xcworkspace -scheme MyScheme -destination 'platform=macOS,arch=x86_64'

          Tests the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace using the destination described as My Mac 64-bit in Xcode.

 xcodebuild -exportArchive -archivePath MyMobileApp.xcarchive -exportPath ExportDestination -exportOptionsPlist 'export.plist'

          Exports the archive MyMobileApp.xcarchive to the path ExportDestination using the options specified in export.plist.
      
    xcodebuild -exportLocalizations -project MyProject.xcodeproj -localizationPath MyDirectory -exportLanguage zh-hans -exportLanguage es-MX

          Exports two XLIFF files to MyDirectory from MyProject.xcodeproj containing development language strings and translations for Simplified Chinese and Mexican Spanish.

 xcodebuild -exportLocalizations -project MyProject.xcodeproj -localizationPath MyDirectory

          Export a single XLIFF file to MyDirectory from MyProject.xcodeproj containing only development language strings. (In this case, the **-exportLanguage** parameter has been
          excluded.)

 xcodebuild -importLocalizations -project MyProject.xcodeproj -localizationPath MyLocalizations.xliff

          Imports localizations from MyLocalizations.xliff into MyProject.xcodeproj.  Translations with issues will be reported but not imported.

7.SEE ALSO

ibtool(1), sysexits(3), xcode-select(1), xcrun(1), xed(1)
Xcode Builds Settings Reference https://developer.apple.com/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/

macOS June 20, 2016 macOS

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,437评论 0 23
  • 一 过年前公司年会,部门经理范姐跟我们一桌,平时端庄持重的她那天似乎玩得很嗨,我们向她敬酒,她都来者不拒。 可乐啤...
    愚乐园阅读 683评论 0 0
  • 很多年之前,我看过一部电视剧,一开始,男主角的生活浑浑噩噩,直到有一天,他被一群小混混追着躲到了一家剧院,眼前艺术...
    wowowowowowrouw阅读 234评论 4 2
  • 咦。放假一个星期了,却什么都没有做!希望明天开始!重新来过!!加油!还有今天查了一下成绩,发现最难的一科自己居然考...
    稀稀拉拉阅读 125评论 0 0