xctool的使用

xctool https://github.com/facebook/xctool)用以替换苹果公司的 xcodebuild 工具来简化 iOS 和 Mac 项目的构建和测试。

要使用该工具必须安装 Xcode 命令行工具:From Xcode, install via Xcode → Preferences → Downloads。


安装xctool工具

// 在终端使用brew安装

brew install xctool

xctool使用命令格式

xctool [BASE OPTIONS] [ACTION [ACTION ARGUMENTS]] ...
Examples:
    xctool [BASE OPTIONS] clean
    xctool [BASE OPTIONS] build [-dry-run] [-skipUnavailableActions]
    xctool [BASE OPTIONS] build-tests [-only TARGET] [-omit TARGET] [-skip-deps]
    xctool [BASE OPTIONS] run-tests [-test-sdk SDK] [-only SPEC] [-omit SPEC] [-freshSimulator] [-resetSimulator] [-newSimulatorInstance] [-noResetSimulatorOnFailure] [-freshInstall] [-parallelize] [-logicTestBucketSize N] [-appTestBucketSize N] [-bucketBy BUCKETBY] [-failOnEmptyTestBundles] [-listTestsOnly] [-targetedDeviceFamily FAMILY] [-testTimeout N] [-logicTest BUNDLE] [-appTest BUNDLE:HOST_APP]
    xctool [BASE OPTIONS] test [-test-sdk SDK] [-only SPEC] [-omit SPEC] [-skip-deps] [-freshSimulator] [-resetSimulator] [-newSimulatorInstance] [-noResetSimulatorOnFailure] [-freshInstall] [-parallelize] [-failOnEmptyTestBundles] [-logicTestBucketSize N] [-appTestBucketSize N] [-bucketBy BUCKETBY] [-listTestsOnly] [-testTimeout N]
    xctool [BASE OPTIONS] archive [-archivePath PATH]
    xctool [BASE OPTIONS] analyze [-only TARGET] [-skip-deps] [-failOnWarnings]
    xctool [BASE OPTIONS] install
Base Options:
    -help                      show help
    -workspace PATH            path to workspace
    -project PATH              path to project
    -scheme NAME               scheme to use for building or testing
    -resultBundlePath PATH     path to bundle to write results from performing a build action
    -find-target TARGET        Search for the workspace/project/scheme to build the target
    -find-target-path PATH     Path to search for -find-target.
    -find-target-exclude-paths Colon-separated list of paths to exclude for -find-target.
    -sdk ALIAS                 alias or path to sdk to use for building (e.g. iphonesimulator, iphonesimulator8.4)
    -configuration NAME        configuration to use (e.g. Debug, Release)
    -destination DESTINATION   use the destination described by DESTINATION (a comma-separated set of key=value pairs describing the destination to use)
    -destination-timeout DESTINwait for TIMEOUT seconds while searching for the destination device
    -jobs NUMBER               number of concurrent build operations to run
    -arch ARCH                 arch to build for (e.g. i386, armv7)
    -toolchain PATH            path to toolchain
    -xcconfig PATH             path to an xcconfig
    -reporter TYPE[:FILE]      add reporter
    -showBuildSettings         display a list of build settings and values
    -showTasks                 show all tasks being spawned by xctool
    -actionScripts             run pre and post action scripts defined in the scheme
    -version                   print version and exit
    -derivedDataPath PATH      override the default derived data path
    -launch-timeout TIMEOUT    simulator launch timeout in seconds (default is 30 seconds)
    SETTING=VALUE              Set the build 'setting' to 'value'
    -DEFAULT=VALUE             Set the user default 'default' to 'value'
Available Reporters:
    json-compilation-database
    json-stream
    junit
    phabricator
    plain
    pretty
    teamcity
    user-notifications
Options for 'build' action:
    -dry-run                   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
Options for 'build-tests' action:
    -only TARGET               build only a specific test TARGET
    -omit TARGET               omit building a specific test TARGET
    -skip-deps                 Only build the target, not its dependencies
Options for 'run-tests' action:
    -test-sdk SDK              SDK to test with
    -only SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
    -omit SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
    -freshSimulator            Start fresh simulator for each application test target
    -resetSimulator            Reset simulator content and settings and restart it before running every app test run.
    -newSimulatorInstance      Start new instance of simulator for each application test target.
    -noResetSimulatorOnFailure Do not reset simulator content and settings if running failed.
    -freshInstall              Use clean install of TEST_HOST for every app test run
    -parallelize               Parallelize execution of tests
    -logicTestBucketSize N     Break logic test bundles in buckets of N test cases.
    -appTestBucketSize N       Break app test bundles in buckets of N test cases.
    -bucketBy BUCKETBY         Either 'case' (default) or 'class'.
    -failOnEmptyTestBundles    Fail when an empty test bundle was run.
    -listTestsOnly             Skip actual test running and list them only.
    -targetedDeviceFamily FAMILTarget specific type of simulator when running tests (1=iPhone, 2=iPad, 4=Apple Watch)
    -testTimeout N             Force individual test cases to be killed after specified timeout.
    -logicTest BUNDLE          Add a path to a logic test bundle to run
    -appTest BUNDLE:HOST_APP   Add a path to an app test bundle with the path to its host app
<pre name="code" class="objc">Options for 'test' action:
    -test-sdk SDK              SDK to test with
    -only SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
    -omit SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
    -skip-deps                 Only build the target, not its dependencies
    -freshSimulator            Start fresh simulator for each application test target
    -resetSimulator            Reset simulator content and settings and restart it before running every app test run.
    -newSimulatorInstance      Create new simulator instance for each application test target
    -noResetSimulatorOnFailure Do not reset simulator content and settings if running failed.
    -freshInstall              Use clean install of TEST_HOST for every app test run
    -parallelize               Parallelize execution of tests
    -failOnEmptyTestBundles    Fail when an empty test bundle was run.
    -logicTestBucketSize N     Break logic test bundles in buckets of N test cases.
    -appTestBucketSize N       Break app test bundles in buckets of N test cases.
    -bucketBy BUCKETBY         Either 'case' (default) or 'class'.
    -listTestsOnly             Skip actual test running and list them only.
    -testTimeout N             Force individual test cases to be killed after specified timeout.

 
<pre name="code" class="objc">Options for 'archive' action:
    -archivePath PATH          PATH where created archive will be placed.
 
<pre name="code" class="objc">Options for 'analyze' action:
    -only TARGET               only analyze selected targets, can be used more than once.
	If this option is specified, its dependencies are assumed to be built.
    -skip-deps                 Skip initial build of the scheme
    -failOnWarnings            Fail builds if analyzer warnings are found


使用场景,如进行脚本生成ipa包(使用终端执行脚本)
<pre name="code" class="objc">#<------------------------------------------------------->
# xcodebuild + xctool

pwd

echo "<----------开始删除旧文件---------->"

# 删除旧文件
rm -rf "archive/log.txt"
rm -rf "archive/zsyDemo.xcarchive"
rm -rf "archive/zsyDemo.ipa"

echo "<----------成功删除旧文件---------->"

echo "<----------开始清除旧项目---------->"

# 重要,执行xcodebuild命令时,必须进入项目目录
# 清空前一次build的项目缓存 
xctool clean -workspace zsyDemo.xcworkspace -scheme zsyDemo -configuration Release >> archive/log.txt

echo "<----------成功清除旧项目---------->"

echo "<----------开始归档archive包---------->"

# 归档(其他参数不指定的话,默认用的是.xcworkspace或.xcodeproj文件里的配置)
# 根据指定的项目、scheme、configuration与输出路径打包出archive文件
xctool -workspace zsyDemo.xcworkspace -scheme zsyDemo archive -archivePath archive/zsyDemo.xcarchive >> archive/log.txt

echo "<----------成功归档archive包---------->"

echo "<----------开始导出ipa包---------->"

# 导出IPA 使用指定的provisioning profile导出ipa
xcodebuild -exportArchive -archivePath archive/zsyDemo.xcarchive -exportPath archive/zsyDemo.ipa -exportFormat ipa -exportProvisioningProfile "zsyDemoDevelopProfile" >> archive/log.txt

echo "<----------成功导出ipa包---------->"

# 输出总用时
echo "<----------Finished. Total time: ${SECONDS}s---------->"

#<------------------------------------------------------->

 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

番薯大佬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值