xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Documentation / xtool.docc / First-app.tutorial
First-app.tutorial161 lines · 7.5 KiBRaw
| 1 | @Tutorial(time: 30) { |
| 2 | @Intro(title: "Build your first iOS app on Linux / Windows") { |
| 3 | Once you've completed <doc:Installation-Linux>, use xtool to build and deploy an iOS app from your Linux/Windows machine. |
| 4 | } |
| 5 | |
| 6 | @Section(title: "Create an xtool project") { |
| 7 | We'll start by creating a project from xtool's default template. |
| 8 | |
| 9 | @Steps { |
| 10 | @Step { |
| 11 | xtool comes with a template for iOS-capable Swift Packages. Run `xtool new` to create a new package. |
| 12 | |
| 13 | @Code(name: "Terminal", file: "template-1b.sh", previousFile: "template-1a.sh") {} |
| 14 | } |
| 15 | |
| 16 | @Step { |
| 17 | At this point, feel free to poke around. |
| 18 | |
| 19 | Observe that the package is structured a lot like a regular SwiftPM library, with a few extra files. |
| 20 | |
| 21 | @Code(name: "Terminal", file: "template-2b.sh", previousFile: "template-2a.sh") {} |
| 22 | } |
| 23 | |
| 24 | @Step { |
| 25 | Read `xtool.yml`. |
| 26 | |
| 27 | This file describes how to bundle the Swift library into an iOS app. At minimum, you need to provide a Bundle ID. This defaults to `com.example.<PackageName>`, in this case `com.example.Hello`. |
| 28 | |
| 29 | @Code(name: "Terminal", file: "template-3b.sh", previousFile: "template-3a.sh") {} |
| 30 | } |
| 31 | |
| 32 | @Step { |
| 33 | Read `.bsp/xtool.json`. |
| 34 | |
| 35 | This file tells your IDE to ask xtool for build information (via the Build Server Protocol). It enables features like syntax highlighting and documentation lookup. |
| 36 | |
| 37 | @Code(name: "Terminal", file: "template-4b.sh", previousFile: "template-4a.sh") {} |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | @Section(title: "Build and run") { |
| 43 | Now that we have a skeleton project, let's get it running on your device. |
| 44 | |
| 45 | @Steps { |
| 46 | @Step { |
| 47 | From inside the package directory, run `xtool dev`. |
| 48 | |
| 49 | The first time you run this, SwiftPM might take a few minutes to build the app. This is because it needs to build the Swift Modules for the iOS SDK. Subsequent runs should be a lot faster since SwiftPM caches these modules globally. |
| 50 | |
| 51 | @Code(name: "Terminal", file: "build-1b.sh", previousFile: "build-1a.sh") |
| 52 | } |
| 53 | |
| 54 | @Step { |
| 55 | After the build is complete, xtool will attempt to install it on your device. |
| 56 | |
| 57 | At this point, connect your iOS device to your computer via USB. If you installed `libimobiledevice-utils` during setup, you can verify that your device is connected by running `ideviceinfo`. xtool will continue after automatically detecting that your device is connected. |
| 58 | |
| 59 | @Code(name: "Terminal", file: "build-2.sh", reset: true) |
| 60 | } |
| 61 | |
| 62 | @Step { |
| 63 | Pair your device if prompted. |
| 64 | |
| 65 | The first time you run `xtool dev`, you may see a "Trust" dialog on your iOS device to proceed with pairing. Tap **Trust** and enter your passcode on iOS. xtool may throw an error after this: if so, just run `xtool dev` again. |
| 66 | |
| 67 | @Code(name: "Terminal", file: "build-2.sh", reset: true) { |
| 68 | @Image(source: "Trust", alt: "Prompt alerting user to trust device") |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | @Step { |
| 73 | xtool will now connect to Apple Developer Services, register your device with your Apple ID, generate a Certificate + App ID + Provisioning Profile, sign the app, and then install it. |
| 74 | |
| 75 | @Code(name: "Terminal", file: "build-3.sh", reset: true) {} |
| 76 | } |
| 77 | |
| 78 | @Step { |
| 79 | Enable Developer Mode if needed. |
| 80 | |
| 81 | At this point, you may run into an error asking you to enable **Development Mode** on your iOS device. Follow [these instructions](https://developer.apple.com/documentation/xcode/enabling-developer-mode-on-a-device) and then run `xtool dev` again. |
| 82 | |
| 83 | @Code(name: "Terminal", file: "build-3.sh", reset: true) { |
| 84 | @Image(source: "Developer", alt: "Developer mode in Settings") |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | @Step { |
| 89 | You should now see the app on your iOS device's home screen / App Library. Tap it to launch the app. |
| 90 | |
| 91 | @Image(source: "Home", alt: "Hello app on the home screen") |
| 92 | } |
| 93 | |
| 94 | @Step { |
| 95 | The first time you launch the app, observe that you may get an "Untrusted Developer" alert. |
| 96 | |
| 97 | @Image(source: "UntrustedDev", alt: "Alert prompting user to trust certificate") |
| 98 | } |
| 99 | |
| 100 | @Step { |
| 101 | Go to **Settings** > **General** > **VPN & Device Management** > _[your email]_ > **Trust**. |
| 102 | |
| 103 | @Image(source: "Verified", alt: "Trust settings") |
| 104 | } |
| 105 | |
| 106 | @Step { |
| 107 | You should now be able to launch the app! |
| 108 | |
| 109 | @Image(source: "HelloWorld", alt: "Hello world app") |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | @Section(title: "Edit and re-run") { |
| 115 | We'll make a small change to the app in your favorite code editor, and then re-run it. |
| 116 | |
| 117 | @Steps { |
| 118 | @Step { |
| 119 | Follow the instructions to configure [SourceKit-LSP](https://github.com/swiftlang/sourcekit-lsp/blob/242609dcad55824d9eb23269c0aeead187fd0faa/Documentation/Editor%20Integration.md) for your IDE. |
| 120 | |
| 121 | For example, if you're using Visual Studio Code, this means you need to install the [Swift extension](https://marketplace.visualstudio.com/items?itemName=swiftlang.swift-vscode). If you're on Windows, make sure you're [connected to the WSL remote](https://code.visualstudio.com/docs/remote/wsl). |
| 122 | |
| 123 | @Image(source: "SwiftExtension", alt: "Swift extension for VSCode") |
| 124 | } |
| 125 | |
| 126 | @Step { |
| 127 | Open the project folder in your editor, and drill down to `Sources/Hello/ContentView.swift`. |
| 128 | |
| 129 | @Code(name: "ContentView.swift", file: "edit-2.swift") {} |
| 130 | } |
| 131 | |
| 132 | @Step { |
| 133 | If you've configured SourceKit-LSP correctly, you should see rich documentation when you hover over the various types and methods. |
| 134 | |
| 135 | @Code(name: "ContentView.swift", file: "edit-2.swift") { |
| 136 | @Image(source: "Hover", alt: "Intellisense") |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | @Step { |
| 141 | Let's update the "Hello, world!" text to be bold and purple. |
| 142 | |
| 143 | @Code(name: "ContentView.swift", file: "edit-4.swift") {} |
| 144 | } |
| 145 | |
| 146 | @Step { |
| 147 | Run `xtool dev` again to re-build and re-install. This should go a lot faster than the first time. |
| 148 | |
| 149 | @Code(name: "Terminal", file: "rerun-5b.sh", previousFile: "rerun-5a.sh") {} |
| 150 | } |
| 151 | |
| 152 | @Step { |
| 153 | Launch the app again to see the updated text! |
| 154 | |
| 155 | @Code(name: "Terminal", file: "rerun-6.sh") { |
| 156 | @Image(source: "HelloWorld-Purple", alt: "Updated Hello app") |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |