xtool 跨平台 iOS 开发实践指南:用 SwiftPM 在 Linux、Windows 与 macOS 上构建、签名并部署 iOS 应用
xtool 跨平台 iOS 开发实践指南:用 SwiftPM 在 Linux、Windows 与 macOS 上构建、签名并部署 iOS 应用
导读:本文以 xtool 官方文档(Documentation/xtool.docc/xtool.md)为主线,系统讲解这款跨平台 Xcode 替代工具的核心能力、安装配置、
xtool.yml打包配置、首个 iOS 应用的构建部署流程,以及 App Extension 的创建方法。阅读本文后,你将能在不使用 Xcode 构建系统的前提下,仅凭 SwiftPM 与命令行在 Linux/WSL/macOS 上完成 iOS 应用的构建、签名、安装、运行与调试全流程,并能从源码层面理解其底层实现原理。
xtool 是一个跨平台(Linux/WSL/macOS)的命令行工具,目标是用开源标准复刻 Xcode 的核心功能。根据官方文档的 Overview,它具备三大核心能力:
- 将 SwiftPM 包构建为 iOS 应用(Build a SwiftPM package into an iOS app)
- 为 iOS 应用签名并安装到设备(Sign and install iOS apps)
- 以编程方式与 Apple Developer Services 交互(Interact with Apple Developer Services programmatically)
如上图所示,xtool 可在 Linux 桌面的编辑器中完成从代码补全到 xtool dev 构建部署的完整闭环:左侧是 xtool new 生成的 Hello 项目结构,编辑器中提供 SwiftUI 代码补全,底部终端实时展示构建与安装进度。
一、安装与初始化
xtool 的安装分为 Linux/Windows 与 macOS 两条路径,官方文档分别对应 Installation-Linux.md 与 Installation-macOS.md。
1.1 Linux / Windows(WSL)安装
在 Linux(或 Windows 的 WSL 环境)上,需要依次准备以下前置条件:
WSL(仅 Windows 用户):Windows 用户可借助 Windows Subsystem for Linux 使用 xtool。安装 WSL 后还需配置 USB 直通(USBIPD),确保 iOS 设备能够通过 USB 绑定到 WSL。若在真机通信中遇到 Error: AFCClient.Error.muxError,官方提示可以改用 iTunes 在 Windows 侧中继设备连接,而不依赖 USBIPD。
Swift 工具链:安装 Swift 6.4 工具链(文档建议版本),并确认安装正确:
swift --version
# Swift version 6.4 (swift-6.4-RELEASE)
usbmuxd:xtool 依赖 usbmuxd 与 iOS 设备通信。可先检查是否已安装:
usbmuxd --help
# Usage: usbmuxd [OPTIONS]
# ...
若提示 command not found,在 Ubuntu/Debian 上通过以下命令安装:
sudo apt-get install usbmuxd
usbmuxd 属于 libimobiledevice 项目。官方还建议安装 libimobiledevice-utils 以获取 ideviceinfo 等工具,方便从命令行查看设备信息:
sudo apt-get install libimobiledevice-utils
ideviceinfo
# DeviceName: Kabir's iPhone
# SerialNumber: ...
# UniqueDeviceID: ...
Xcode.xip:下载 Xcode 27(当前仓库文档所依赖的版本),并记下 Xcode.xip 的保存路径。注意该下载地址需要 Apple ID 登录鉴权,应在浏览器中访问而非直接使用 curl。
完成上述准备后,下载最新版 xtool.AppImage(按架构选择),重命名为 xtool 并放入 PATH:
curl -fL \
"https://github.com/xtool-org/xtool/releases/latest/download/xtool-$(uname -m).AppImage" \
-o xtool
chmod +x xtool
sudo mv xtool /usr/local/bin/
验证安装:
xtool --help
# OVERVIEW: Cross-platform Xcode replacement
# ...
1.2 macOS 安装
macOS 上并不依赖 Xcode 的构建系统,但仍需安装 Xcode 以获得 iOS SDK 与工具链。安装后确认 iOS SDK 与 Swift 就绪:
xcrun -sdk iphoneos -show-sdk-path
# /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.4.sdk
swift --version
# swift-driver version: 1.120.5 Apple Swift version 6.1 ...
xtool 本体可通过 Homebrew 安装:
brew install xtool-org/tap/xtool
也可以从 GitHub Releases 下载 xtool.app,放入 /Applications 后运行其中提供的脚本,将 xtool 命令加入 PATH。手动安装需要自行关注新版发布;如需自动更新(Sparkle),可参考仓库中提出的相关 issue 并贡献代码。
1.3 一次性配置:xtool setup
在 SetupCommand.swift 中可以看到,xtool setup 等价于依次执行 xtool auth && xtool sdk——先完成与 Apple 的鉴权,再为 SwiftPM 安装 iOS SDK。
运行 xtool setup 后,首先进入登录模式选择:
Select login mode
0: API Key (requires paid Apple Developer Program membership)
1: Password (works with any Apple ID but uses private APIs)
Choice (0-1):
两种登录模式各有适用场景(对应 AuthCommand.swift 中的 AuthMode 枚举):
| 模式 | 适用条件 | 技术特点 |
|---|---|---|
| API Key | 已加入付费 Apple Developer Program | 基于公开的 App Store Connect API,需生成具备 App Manager 角色的 Team Key(Key ID、Issuer ID 与 .p8 文件),官方推荐 |
| Password | 任意 Apple ID(含免费账号) | 依赖 Apple 私有 API 完成鉴权,官方建议使用一次性 Apple ID 以降低风险 |
无论选择哪种方式,凭据都只会发送给 Apple,不会发送给其他任何服务。完成登录后,setup 会要求输入此前下载的 Xcode.xip 路径:
Choice (0-1): 0
...
Path to Xcode.xip:
输入路径(例如 ~/Downloads/Xcode_27.0.xip)后,xtool 会解包 Xcode,为其生成并安装一套 iOS Swift SDK。验证安装结果:
swift sdk list
# darwin
1.4 命令体系总览
从 XTool.swift 的 XToolCommand 配置可以看出,xtool 将全部子命令划分为三个命令组:
- Configuration(配置):
setup、auth、sdk - Development(开发):
new、dev、ds - Device(设备):
devices、install、uninstall、launch
其中 auth 包含 login/logout/status 子命令,sdk 包含 install/update/remove/build/status 子命令,dev 则包含 build、run、generate-xcode-project、build-server 四个子命令(默认执行 run)。
二、创建并运行你的第一个 iOS 应用
官方教程 First-app.tutorial 以 30 分钟为跨度,演示了从零到真机运行 Hello 应用的完整流程。
2.1 生成项目:xtool new
xtool 内置了 iOS 能力的 SwiftPM 模板,执行:
xtool new Hello
Creating package: Hello
Creating Package.swift
Creating xtool.yml
Creating .gitignore
Creating .bsp/xtool.json
Creating Sources/Hello/HelloApp.swift
Creating Sources/Hello/ContentView.swift
Finished generating project Hello.
从 NewCommand.swift 的源码可见,模板会生成一个与普通 SwiftPM 库非常相似的项目结构,附带少量额外文件:
Hello/
├── .gitignore
├── .bsp/xtool.json
├── Package.swift
├── Sources/Hello/
│ ├── HelloApp.swift
│ └── ContentView.swift
└── xtool.yml
模板 Package.swift 要求一个 xtool 项目恰好包含一个 library product(代表主应用),平台声明为 .iOS(.v17) 与 .macOS(.v14)。包名校验规则为:首字符只能是 [a-z, A-Z, _],其余字符只能是 [a-z, A-Z, 0-9, _, -]。
xtool new 默认会先执行 xtool setup 补齐缺失的鉴权与 SDK 步骤,可用 --skip-setup 跳过。
2.2 两个关键文件
xtool.yml:描述如何将 Swift 库打包成 iOS 应用。最小配置只需提供 Bundle ID:
version: 1
bundleID: com.example.Hello
bundleID 默认为 com.example.<PackageName>(本例即 com.example.Hello)。
.bsp/xtool.json:Build Server Protocol 配置文件,告诉 IDE 通过 xtool 获取构建信息,从而获得语法高亮、文档查看等能力。其内容为:
{
"name": "xtool",
"version": "1.0",
"bspVersion": "2.2.0",
"languages": ["c", "cpp", "objective-c", "objective-cpp", "swift"],
"argv": ["/usr/bin/env", "xtool", "dev", "build-server"]
}
该文件由 LSPConfig.swift 自动生成:若 Swift 版本支持 swiftbuild 则优先写入 .bsp/xtool.json,否则回退到 .sourcekit-lsp/config.json(legacy 模式)。若不想让 xtool 自动生成,可在 xtool.yml 中设置 skipLSP: true。
2.3 构建与部署:xtool dev
在包目录下运行 xtool dev。首次运行 SwiftPM 需要为 iOS SDK 构建 Swift Modules,可能需要几分钟;此后 SwiftPM 会全局缓存这些模块,再次构建会快很多:
Hello$ xtool dev
Planning...
Building for debugging...
[8/8] Linking Hello-App
Build of product 'Hello-App' complete! (4.94s)
Waiting for device to be connected...
Installing to device: Kabir's iPhone (udid: *****)
[Unpacking app] 100%
[Logging in] 100%
[Preparing device] 100%
[Provisioning] 100%
[Signing] 100%
[Packaging] 100%
[Connecting] 100%
[Installing] 100%
[Verifying] 100%
构建完成后,xtool 会等待设备接入(可先用 ideviceinfo 确认设备已被识别)。随后它会连接 Apple Developer Services,自动完成:注册设备、生成 Certificate + App ID + Provisioning Profile、签名、安装这一整套流水线。
首次运行时可能遇到的交互:
- 信任弹窗:iOS 设备上会弹出 "Trust" 对话框,点击 Trust 并输入锁屏密码。若随后 xtool 报错,重新运行
xtool dev即可。 - 开发者模式:若提示需要开启 Development Mode,按 Apple 官方指引在设备上启用后再执行
xtool dev。 - 未受信任的开发者:首次启动应用可能出现 "Untrusted Developer" 警告,需进入 设置 > 通用 > VPN 与设备管理,信任对应开发者证书后即可正常启动应用。
2.4 编辑并重新运行
配置 SourceKit-LSP(例如在 VSCode 中安装 Swift 扩展;Windows 用户需先连接到 WSL Remote),打开项目并定位到 Sources/Hello/ContentView.swift。在代码上悬停即可看到丰富的类型与方法文档。修改 "Hello, world!" 为粗体紫色:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
.bold()
.foregroundStyle(.purple)
}
.padding()
}
}
再次运行 xtool dev 完成重新构建与安装,重新启动应用即可看到更新后的界面。仓库示例 Examples/DemoSimple 与 Examples/DemoDynamic 提供了可直接运行的最小项目,可作为参考。
三、xtool.yml 打包配置详解
Control.md 详细讲解了如何通过 xtool.yml 控制应用包(.app)的结构。若项目尚未生成该文件,可手动创建:
cat > xtool.yml << EOF
version: 1
bundleID: com.example.Hello
EOF
从 PackSchema.swift 的 PackSchemaBase 结构可以完整梳理出 xtool.yml 支持的全部键:
| 键 | 类型 | 含义 |
|---|---|---|
version |
Int | 配置模式版本,当前仅支持 1,其他值会报 Unsupported schema version |
bundleID |
String | 应用 Bundle ID,与 orgID 二选一 |
orgID |
String | 组织 ID,与 bundleID 二选一;缺失时默认 com.example |
product |
String | 指定作为主应用的 SwiftPM library product 名称(多 product 时必填) |
infoPath |
String | 自定义 Info.plist 路径(相对项目根目录) |
entitlementsPath |
String | 自定义 entitlements 文件路径 |
iconPath |
String | 应用图标路径(必须是 png 后缀,否则校验报错) |
resources |
[String] | 直接复制到 .app 根目录的文件列表 |
skipLSP |
Bool | 跳过自动生成 LSP 支持文件 |
extensions |
[{...}] | App Extension 声明列表(详见第四章) |
其中 bundleID 与 orgID 的互斥关系在源码中明确:两者都缺省会抛 Must specify either orgID or bundleID;都提供时优先使用 bundleID。iconPath 在 PackSchema.init(validating:) 中强制要求 .png 扩展名。
3.1 修改 Bundle ID
编辑 bundleID 字段即可。需要注意:xtool 在真机签名安装时会为 Bundle ID 加前缀,例如 com.example.Hello 可能变成 XTL-1234.com.example.Hello。原因是至少对免费账号(未加入付费开发者计划)而言,两个账号不能使用同一个 Bundle ID,前缀化可以避免共享应用时出现冲突。官方文档提到,若投入额外工程,未来可通过对付费开发者计划用户使用通配符 provisioning profile 来解除此限制。
3.2 自定义 Info.plist
xtool 会为应用自动生成一份精简的 Info.plist,但允许通过 infoPath 提供一份"增量补丁"——只包含需要新增或覆盖的键:
infoPath: path/to/Info.plist
例如创建如下文件,将默认的竖屏(portrait)方向改为仅横屏,并新增显示名称:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleDisplayName</key>
<string>My App</string>
</dict>
</plist>
合并规则由 Planner.swift 的 product(...) 实现:xtool 先基于默认键构造 infoPlist(包括 CFBundleIdentifier、MinimumOSVersion、UISupportedInterfaceOrientations(默认 portrait)等),再通过 infoPlist.merge(info, uniquingKeysWith: { $1 }) 将用户提供的键覆盖进去。运行 xtool dev build 后,可检查 ./xtool/YourApp.app/Info.plist 查看合并结果。
3.3 复制资源
方式一:SwiftPM Resources。图片等非代码资源可直接利用 SwiftPM 的资源机制,"开箱即用"。例如 Sources/Hello/Blob.png,在 Package.swift 中声明:
targets: [
.target(
name: "Hello",
resources: [.copy("Blob.png")]
),
]
在界面中加载:
Image("Blob", bundle: Bundle.module)
方式二:顶层资源(top-level resources)。SwiftPM 资源会被复制到 .app 内嵌套的 .bundle 目录中;如果某些文件必须位于应用包根目录(例如 Firebase 的 GoogleServices-Info.plist),可在 xtool.yml 中声明:
resources:
- Resources/GoogleServices-Info.plist
该文件会被复制到 Hello.app/GoogleServices-Info.plist。在 Planner.swift 中,这类资源对应 Plan.Resource.root(source:);Packer.swift 会通过 packFileToRoot 将其直接拷入 .app 根目录。除 .root 外,Plan.Resource 还支持 .bundle(SwiftPM target 资源)、.binaryTarget(二进制框架)、.library(动态库)等类型,后者会以符号形式拷入 Frameworks/ 目录。
3.4 设置应用图标
将 Resources/AppIcon.png 设置为图标:
iconPath: Resources/AppIcon.png
图标必须是 png,官方建议分辨率 1024x1024px。打包时 Packer.swift 会把图标复制到 .app 根目录,并在 Info.plist 中写入 CFBundleIconFile。
3.5 添加 Entitlements
需要特殊能力时(例如连接 HomeKit 设备所需的 com.apple.developer.homekit),先创建 App.entitlements:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.homekit</key>
<true/>
</dict>
</plist>
再通过 xtool.yml 指定:
entitlementsPath: App.entitlements
底层流程见 DevCommand.swift 的 PackOperation.run():打包完成后,xtool 会解析所有 product 的 entitlements 文件,交由 Signer 以 ad-hoc 身份执行签名。
官方同时给出以下排障要点:
- 部分 entitlement(如 Network Extension)不适用于免费开发者账号,需加入付费开发者计划。
- 部分 entitlement(如 User Notifications Filtering)需要 Apple 特别授权,即使有权限也不保证可用。
- 许多 entitlement 要求在 Developer Services 门户启用对应 "Capability",xtool 会自动处理已实现的映射;若遇到尚未支持的 Capability,可在仓库中提交 issue。
四、创建 App Extension
Appex.md 以 Widget Extension 为例,演示了如何为 xtool 应用添加 App Extension。iOS 的扩展点包括 Widgets、Share Extensions、Safari Extensions 等,其他类型扩展的步骤类似。仓库中的 Examples/DemoExtensions 是这一流程的真实可运行样例。
前提:已有一个可运行的 xtool 应用(参考第二章创建)。
4.1 Step 1:在 Package.swift 中新增 product
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "Hello",
platforms: [.iOS(.v17)],
products: [
.library(
name: "Hello",
targets: ["Hello"]
),
+ .library(
+ name: "HelloWidget",
+ targets: ["HelloWidget"]
+ ),
],
targets: [
.target(name: "Hello"),
+ .target(name: "HelloWidget"),
]
)
4.2 Step 2:更新 xtool.yml
现在包内有两个 product,需要告诉 xtool 哪个是主应用、哪个是扩展:
version: 1
bundleID: com.example.Hello
+ product: Hello
+ extensions:
+ - product: HelloWidget
+ infoPath: HelloWidget-Info.plist
从 PackSchema.swift 可以看到,extensions 数组中每一项支持 product、bundleID、infoPath、resources、entitlementsPath 字段。在 Planner.swift 中,扩展 product 的 Bundle ID 默认继承主应用的 orgID 前缀(也可单独指定 bundleID),类型为 .appExtension,打包后位于 .app/PlugIns/<name>.appex 目录,并声明 CFBundlePackageType 为 XPC!。
4.3 Step 3:创建扩展的 Info.plist
App Extension 必须提供描述自身类型的 Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
com.apple.widgetkit-extension 表示 Widget Extension;其他扩展类型的 NSExtensionPointIdentifier 取值不同,还可能用到 NSExtensionPrincipalClass 等键。此外需要注意扩展框架的演进:Apple 正在从传统的 Foundation Extensions(NSExtension -> EXAppExtensionAttributes、NSExtensionPointIdentifier -> EXExtensionPointIdentifier)迁移到 ExtensionKit;xtool 目前尚未支持 ExtensionKit(已列入计划)。
4.4 Step 4:编写 Widget 代码
创建 Sources/HelloWidget/Widget.swift:
import WidgetKit
import SwiftUI
@main struct Bundle: WidgetBundle {
var body: some Widget {
HelloWidget()
}
}
struct HelloWidget: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: "HelloWidget",
provider: Provider()
) { entry in
VStack {
Text(entry.date, style: .date)
}
.containerBackground(.fill.tertiary, for: .widget)
}
.configurationDisplayName("HelloWidget")
.description("This is an example widget.")
}
struct Entry: TimelineEntry {
var date = Date()
}
struct Provider: TimelineProvider {
func placeholder(in context: Context) -> Entry {
Entry()
}
func getSnapshot(
in context: Context,
completion: @escaping (Entry) -> Void
) {
completion(Entry())
}
func getTimeline(
in context: Context,
completion: @escaping (Timeline<Entry>) -> Void
) {
completion(Timeline(
entries: [Entry()],
policy: .after(.now + 3600)
))
}
}
}
(文档也善意提醒:每小时刷新一次仅用于演示,并非生产级 WidgetKit 实践。)
最后运行 xtool dev,即可在小组件库中找到 HelloWidget 并添加到主屏幕。在打包层面,扩展的链接参数由 Packer.swift 中的 linkerSettings 决定:扩展以 _NSExtensionMain 作为入口(链接 Foundation 框架),并同时设置指向宿主应用与自身 Frameworks 目录的 rpath。
五、设备管理与 Apple Developer Services
5.1 设备相关命令
xtool devices:列出已连接的设备,支持--search指定搜索模式、--no-wait不等待;未发现设备时默认等待连接(见 DevicesCommand.swift)。xtool install <path>:将.app或.ipa安装到真机(见 InstallCommand.swift)。xtool uninstall <bundleID>:从设备卸载应用(见 UninstallCommand.swift)。xtool launch <bundleID> <a href="https://link.gitcode.com/i/b94c76cef2c31acfb954b8183933d086" target="_blank">args...]:通过 debugserver 启动已安装应用并传递启动参数(见 [LaunchCommand.swift)。
这些命令均通过 ConnectionOptions(见 ConnectionOptions.swift)等待设备接入:未指定 --udid 时会列出候选设备供选择,可指定 --search 限定 USB 或 Wi-Fi 连接方式。
5.2 Developer Services(xtool ds)
ds 命令组用于以编程方式交互 Apple Developer Services,包含 ds teams、ds devices、ds identifiers、ds certificates、ds profiles 等子命令(见 DSCommands 目录),可用于查询团队、管理设备注册、查看 App ID 与证书、拉取 provisioning profile 等运维操作。
六、底层原理:从 SwiftPM 包到安装到设备的完整流水线
6.1 规划与打包(Planner → Packer)
xtool dev build 的核心流程在 DevCommand.swift 的 PackOperation.run() 中:
- 校验当前目录存在
Package.swift; - 确保 Darwin SDK 就绪(
EnsureSDKOperation); - 加载
xtool.yml(缺失时使用orgID: com.example默认配置并给出警告); - 确保 LSP 配置文件存在;
Planner解析 SwiftPM 包图(通过swift package show-dependencies与swift package describe),确定主应用与扩展的 product、Bundle ID、资源与 entitlements,生成Plan;Packer构造一个临时 builder package,以--disable-automatic-resolution方式调用 SwiftPM 编译,再把产物与资源、Info.plist、图标、框架按目标结构组装成xtool/<App>.app。
Packer 的产物既可以是 .app,也可经 zipCompressor 压缩为 .ipa(dev build --ipa)。默认构建 triple 为 arm64-apple-ios,可通过 --triple 覆盖;macOS 上 dev run --simulator 会改用 arm64-apple-ios-simulator 并通过 xcrun simctl install 安装到模拟器。
6.2 Darwin SDK 的生成(SDKBuilder)
Linux 上使用的 iOS SDK 并非下载成品,而是由 SDKBuilder.swift 从 Xcode.xip 现场构建:
- 通过
libunxip流式解包 XIP,并按 SDKEntry 的白名单过滤——只保留Toolchains/XcodeDefault.xctoolchain/usr/lib/{swift,swift_static,clang}与Platforms/{iPhoneOS,MacOSX,iPhoneSimulator}相关文件; - 下载 darwin-tools(
ld64.lld、llvm-lib等)与 OpenAppleMacros(宏插件服务器),写入toolset.json/toolset-swb.json; - 生成
swift-sdk.json,声明arm64-apple-ios、arm64/x86_64-apple-ios-simulator、arm64/x86_64-apple-macosx五个目标 triple; - 将
XCTest、Testing等框架符号链接进 SDK,并让swift-plugin-server指向 OpenAppleMacrosServer。
SDK 有两种形态:--slim 精简版(省磁盘、无法原地更新)与普通版(保留完整 Xcode.app Developer 目录,支持 xtool sdk update 原地升级)。xtool sdk build <xip> <out> 可手动构建,xtool sdk install / remove / status 负责安装管理。SDK 带版本标识(epoch=3),过期时 xtool 会自动提示重建。
6.3 签名与安装(IntegratedInstaller → AutoSigner)
IntegratedInstaller.swift 展示了从 .app/.ipa 到真机的完整安装流水线,阶段依次为 Unpacking app → Preparing device →(sign-in-place:登录、注册设备、Provisioning、Signing)→ Packaging → Connecting → Installing → Verifying,与 xtool dev 终端输出一一对应:
- 解包或解压
.app/.ipa到临时目录; - 通过 lockdown 与设备握手(含配对待命逻辑:设备锁定或配对弹窗未确认时会提示并重试);
signInPlace调用 AutoSigner.swift 自动完成证书、App ID、描述文件的创建/复用,并对应用与扩展签名;- 重新压缩为
.ipa后,经AppInstaller推送安装到设备。
配对交互(Trust 弹窗)与开发者模式提示正是由这一层的 Message.pairDevice / Message.unlockDevice 等状态驱动的,与 First-app.tutorial 中的操作步骤吻合。
七、总结与后续学习路径
至此,你已掌握 xtool 的完整使用链路:在 Linux/WSL/macOS 上完成安装与登录(setup)、生成 SwiftPM 项目(new)、构建部署(dev)、通过 xtool.yml 定制应用包结构,以及为应用添加 App Extension。仓库中还提供了丰富的实战样例可供继续探索:
- Examples/DemoSimple:最小可运行项目
- Examples/DemoDynamic:动态库集成示例
- Examples/DemoResources:资源打包示例(含 SwiftPM 资源与 bundled.txt)
- Examples/DemoExtensions:Widget 扩展完整示例
- Examples/DemoTCA:集成 The Composable Architecture 的示例
更进一步,可阅读 XToolSupport 中各命令的实现、PackLib 中 Planner/Packer/Schema 的打包逻辑,以及 Tests/XToolTests 下的单元测试(如 PackerTests、DarwinSDKTests、MatcherTests),从源码层面理解并验证本文所述的各项机制。如果在使用中遇到 entitlement 映射、扩展类型或 SDK 构建相关的缺失功能,欢迎到仓库提交 issue 反馈。
