Xcode命令行教程
前言
虽然平常我们使用 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 usexcode-select --install
to install the standalone command line developer tools.
Seeman 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
, andmac-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 | Usage: xcrun [options] <tool name> ... arguments ... |
参考资料
文档信息
- 版权声明:自由转载-保持署名-非商用-非衍生 ( CC BY-NC-ND 4.0 )