xcodebuild命令详解

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xcodebuild命令详解相关的知识,希望对你有一定的参考价值。

参考技术A

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

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.

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

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.

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.

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

使用 xcodebuild 命令行工具导出失败错误

【中文标题】使用 xcodebuild 命令行工具导出失败错误【英文标题】:EXPORT FAILED error using xcodebuild command line tool 【发布时间】:2015-11-24 18:27:27 【问题描述】:

我正在尝试通过 xcodebuild 导出 ipa 文件,但总是收到此错误。

IDEDistribution: 步骤失败: : Error Domain=IDEDistributionErrorDomain Code=14 "No 找到适用的设备。” UserInfo=NSLocalizedDescription=No 找到适用的设备。 错误:exportArchive:没有适用的设备 找到了。

Error Domain=IDEDistributionErrorDomain Code=14 "没有适用的设备 找到。" UserInfo=NSLocalizedDescription=未找到适用的设备。

** 导出失败 **

有什么提示吗?

这是我正在使用的 shell 脚本(通过sh export_script.sh 在终端中运行)

xcodebuild clean -project 'MyProject.xcodeproj' -configuration Debug -scheme MyProject -alltargets
xcodebuild -project 'MyProject.xcodeproj' -scheme MyProject archive -archivePath 'MyProject.xcarchive'
xcodebuild -exportArchive -archivePath 'MyProject.xcarchive' -exportPath 'Export' -exportOptionsPlist 'Options.plist'

附:指出我的脚本中的任何错误(如果存在)。

【问题讨论】:

xcodebuild: "No applicable devices found." when exporting archive的可能重复 【参考方案1】:

我不确定,但可能你应该指定你需要一个设备的构建。

【讨论】:

【参考方案2】:

您需要添加适当的值-sdk(取决于iphoneos的版本号)

【讨论】:

【参考方案3】:

旧的方法似乎可以完成这项工作。

xcodebuild -exportArchive -archivePath $XCODE_ARCHIVE -exportPath $EXPORT_PATH -exportFormat ipa -exportProvisioningProfile "$PROVISIONING_PROFILE" -configuration $CONFIGURATION

其中$PROVISIONING_PROFILE 是例如iOS Development。存档已正确创建。 shell 将打印出弃用日志。您可以放心地忽略它。

Xcode 引入的新方法不起作用(至少对我而言)。见xcodebuild's new exportOptionsPlist flag。

如果您有任何使用新方式的提示,请发布。

编辑

有一个开放的雷达Open Radar。另外,Fastlane 也为这个问题提供了一种回退机制(见Export Failed with Xcode 7 - No applicable devices found)。

【讨论】:

【参考方案4】:

就我而言,问题与使用 RVM 有关。切换到系统 Ruby 解决了这个问题:

rvm use system 

xcodebuild 的某些部分这样的接缝依赖于 Ruby 的系统版本,不能很好地与 RVM 配合使用。

【讨论】:

以上是关于xcodebuild命令详解的主要内容,如果未能解决你的问题,请参考以下文章

linux 操作系统笔记基础命令

1小时教会你玩转linux 操作系统

fsck 命令详解

xcodebuild命令

ab 命令详解

通过 xcodebuild 命令更改目标属性