文章目录
  1. 1. 前言
  2. 2. 背景
  3. 3. 用法
    1. 3.1. xcode-select
    2. 3.2. xcodebuild
    3. 3.3. xcrun
  4. 4. 参考资料
  5. 5. 文档信息

前言


虽然平常我们使用 Xcode IDE 进行打包,但还是有必要了解一下熟悉 Xcode 命令行的用法。市场上有很多基于这方面的工具,比如:fastlane, 这个工具现在比较流行,当然我们还可以自定义属于我们的需求的打包方式。

Xcode 内置 CommandLineTools ,所带的工具也是非常的完美。Apple 还将 CommandLineTools 从 Xcode 剥离出来,供大家使用。

注:若我们自己下载的命令行安装包,如果想移除的话,直接删除 /Library/Developer/CommandLineTools 文件即可。

背景


当时我想在机器上实现 2 个版本的命令行工具,以供 fastlane 编译打包时可以选择不同版本工具。当时以为下载安装低版本 CommandLineTools 工具,然后安装最新公布的 Xcode 就可以啦,但是事情超出了我的预料。

CommadnLineTools 安装路径为 /Library/Developer/CommandLineTools,xcode-select -p 打印出的路径也是相同的。当时 fastlane 提示 xcodebuild 必须要求 Xcode,无奈放弃了这个想法,改用机器有 2 个 Xocde 方案。以高版本IDE为主,当需要使用低版本的命令行工具时,进行切换配置。

Xcode版本切换方法有两种,一种是图形界面形式,另一种命令行形式。
1、图形界面: Xcode -> Preferences -> locations -> Command Line Tools -> 选择合适版本;
2、命令行:sudo xcode-select –switch [xcode版本所在路径(eg:/Users/guogong/Desktop/Xcode.app/Contents/Developer)]

注:若您想到解决 低版本命令 + Xcode 解决 2 个版本编译打包方法,欢迎联系我。谢谢。

用法


xcode-select


Use sudo xcode-select --switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools, or use xcode-select --install to install the standalone command line developer tools.
See man xcode-select for more details.

单独安装命令行

1
$ xcode-select --install

获取当前命令行链接路径:

1
2
$ xcode-select -p
/Library/Developer/CommandLineTools

选择 Xcode 命令行版本

1
$ sudo xcode-select --switch path/to/Xcode.app

获取更多信息

1
$ man xcode-select

xcodebuild


查看工具帮助命令:xcodebuild -h

method : String
Describes how Xcode should export the archive. Available options: app-store, package, ad-hoc, enterprise, development, developer-id, and mac-application. The list of options varies based on the type of archive. Defaults to development.

-allowProvisioningUpdates
Allow xcodebuild to communicate with the Apple Developer website. For automatically signed targets, xcodebuild will create and update profiles, app IDs, and certificates. For manually signed targets, xcodebuild will download missing or updated provisioning profiles. Requires a developer account to have been added in Xcode’s Accounts preference pane.

归档

1
xcodebuild -workspace Example.xcworkspace -scheme Example -destination 'generic/platform=iOS' -archivePath /../../Example.xcarchive archive | tee /Users.../.../Example-Example.log

xcrun


查看工具帮助命令:xcrun -h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Usage: xcrun [options] <tool name> ... arguments ...

Find and execute the named command line tool from the active developer
directory.

The active developer directory can be set using `xcode-select`, or via the
DEVELOPER_DIR environment variable. See the xcrun and xcode-select manual
pages for more information.

Options:
-h, --help show this help message and exit
--version show the xcrun version
-v, --verbose show verbose logging output
--sdk <sdk name> find the tool for the given SDK name
--toolchain <name> find the tool for the given toolchain
-l, --log show commands to be executed (with --run)
-f, --find only find and print the tool path
-r, --run find and execute the tool (the default behavior)
-n, --no-cache do not use the lookup cache
-k, --kill-cache invalidate all existing cache entries
--show-sdk-path show selected SDK install path
--show-sdk-version show selected SDK version
--show-sdk-build-version show selected SDK build version
--show-sdk-platform-path show selected SDK platform path
--show-sdk-platform-version show selected SDK platform version

参考资料


文档信息


  • 版权声明:自由转载-保持署名-非商用-非衍生 ( CC BY-NC-ND 4.0 )
文章目录
  1. 1. 前言
  2. 2. 背景
  3. 3. 用法
    1. 3.1. xcode-select
    2. 3.2. xcodebuild
    3. 3.3. xcrun
  4. 4. 参考资料
  5. 5. 文档信息