xcodebuild使用总结

官方文档:https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html
xcodebuild是一个命令行工具,可以用来对Xcode工程或工作区进行编译、查找、分析、测试等各种操作。对于如何使用xcode可以参看http://help.apple.com/xcode/mac/8.0/

基本概念

  • workspace 是最大的集合,其可以包含多个 projet,同时可以管理不同的 project 之间的关系。workspace 是以 xcworkspace 的文件形式存在的。workspace 的存在是为了解决原来仅有 project 的时候不同的 project 之间的引用和调用困难的问题
  • project是Xcode对一些代码文件、资源、配置信息的一个管理仓库,可以用来编译产出一个或多个产品。Project包含了多个targets,project有一个被所有targets公用的build setting。
  • targets 表示如何产出一个具体产品,决定了如何对文件进行编译(编译那几个文件,使用什么编译脚本)(通过自己的build setting 和从project继承的build setting)
  • configuration 可以对project和targets中
  • scheme(方案)它不同于上面四个,表示一个组合方案表示那些targets使用什么 build configuration与 executable configuration 。An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute.可以针对编译,运行,单元测试,动态分析,静态代码分析以及打包进行一些配置

命令参数

xcodebuild [-project projectname] [-target targetname ...] [-configuration configurationname]
                [-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
                [-userdefault=value ...]
     xcodebuild [-project projectname] -scheme schemename [-destination destinationspecifier]
                [-destination-timeout value] [-configuration configurationname]
                [-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
                [-userdefault=value ...]
     xcodebuild -workspace workspacename -scheme schemename [-destination destinationspecifier]
                [-destination-timeout value] [-configuration configurationname]
                [-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
                [-userdefault=value ...]
     xcodebuild -version [-sdk [sdkfullpath | sdkname]] [infoitem]
     xcodebuild -showsdks
     xcodebuild -list [-project projectname | -workspace workspacename]
     xcodebuild -exportArchive -exportFormat format -archivePath xcarchivepath -exportPath destinationpath
                [-exportProvisioningProfile profilename] [-exportSigningIdentity identityname]
                [-exportInstallerIdentity identityname]

命令介绍

xcodebuild 构建Xcode project中的一个或多个targets, 也可以构建Xcode workspace或Xcode project的一个scheme。
要构建一个Xcode project, 在你的工程目录下运行xcodebuild. 如果这个目录下有多个project文件则可以使用-project参数用来区分你要编译哪个project. 默认情况下,xcodebuild 构建project中列出的第一个target, 并且使用默认的build configuration. targets在project中的顺序是project的一个属性对所有的使用者来说这个顺序是相同的。
要构建一个Xcode workspace, 必须要使用参数-workspace 和 -scheme 指定构建。 scheme 控制了需要编译那些targets以及这个targets如何被编译。不过也可以通过 xcodebuild的其他参数来从新指定scheme的一些属性.

各个参数意义

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

     -destination destinationspecifier
           Use the destination device described by destinationspecifier.  Defaults to a destination that is
           compatible with the selected scheme.  See the section on destinations 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 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 initiate
           ate a build.

     -derivedDataPath path
           Overrides the folder that should be used for derived data when performing a build action on a
           scheme in a workspace.

     -resultBundlePath path
           Writes a bundle to the specified path with results from performing a build action on a scheme in
           a workspace.

     -exportArchive
           Specifies that an archive should be exported. Requires -exportFormat, -archivePath, and
           -exportPath.  Cannot be passed along with a build action.

     -exportFormat format
           Specifies the format to which the archive should be exported. Valid formats are IPA (iOS archives
           only), PKG (Mac archives only), and APP.  If not specified, xcodebuild will attempt to auto-detect autodetect
           detect the format as either IPA or PKG.

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

     -exportProvisioningProfile profilename
           Specifies the provisioning profile that should be used when exporting the archive.

     -exportSigningIdentity identityname
           Specifies the application signing identity that should be used when exporting the archive.  If
           possible, this may be inferred from -exportProvisioningProfile.

     -exportInstallerIdentity identityname
           Specifies the installer signing identity that should be used when exporting the archive. If pos-sible, possible,
           sible, this may be inferred from -exportSigningIdentity or -exportProvisioningProfile.

     -exportWithOriginalSigningIdentity
           Specifies that the signing identity used to create the archive should be used when exporting the
           archive.
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.

           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.

           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 distribution
                       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 override
           ride all other settings, including settings passed individually on the command line.

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

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

     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.

栗子

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 -destination 'platform=OS X,arch=x86_64'
             test

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

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

             Tests the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace using both the iOS
             Simulator configured as an iPhone and the the iOS device named My iPad.  (Note that the shell
             requires arguments to be quoted or otherwise escaped if they contain spaces.)

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

             Builds the scheme MyScheme in the Xcode workspace MyWorkspace.xcworkspace using the generic
             iOS Device destination.

    xcodebuild -exportArchive -exportFormat IPA -archivePath MyMobileApp.xcarchive -exportPath
             MyMobileApp.ipa -exportProvisioningProfile 'MyMobileApp Distribution Profile'

             Exports the archive MyMobileApp.xcarchive as an IPA file to the path MyMobileApp.ipa using the
             provisioning profile MyMobileApp Distribution Profile.

    xcodebuild -exportArchive -exportFormat APP -archivePath MyMacApp.xcarchive -exportPath MyMacApp.pkg
             -exportSigningIdentity 'Developer ID Application: My Team'

             Exports the archive MyMacApp.xcarchive as a PKG file to the path MyMacApp.pkg using the appli-cation application
             cation signing identity Developer ID Application: My Team.  The installer signing identity
             Developer ID Installer: My Team is implicitly used to sign the exported package.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值