iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🍏

Developing iOS Apps on WSL using Xtool

に公開

Developing iOS Apps on WSL Using Xtool

Introduction

I heard that by using something called Xtool, you can develop for iOS even in a Linux environment, so I decided to give it a try.

Caution

Potential terms of service violations have been pointed out in the forum. Please proceed at your own risk.

1: Environment Setup / Requirements

The following are required:

One of the following combinations is required:

Additionally, the following notation is used in this article:

$ -> WSL: Execute as a general user
> -> Windows: Execute as a general user
! -> Windows: Execute as Administrator

<Placeholder> (Example: cat /home/<username>/.ssh/id_ed25519)

Environment at the time of writing

  • Windows 11
  • WSL: Ubuntu 24.04.2 LTS x86_64
  • usbmuxd: 1.1.1
  • xtool: 1.11.0
  • usbipd-win: 5.0.0

2: Xtool Setup

  1. Download Xcode.xip.

You can download it from the following URL. Downloading via curl or similar is not possible (learned the hard way).
https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_16.3/Xcode_16.3.xip
At this time, you need to remember the path where you saved the download. Since it is only used once, /tmp should be fine (needs verification).
Also, it is recommended to check if it was downloaded correctly using the file command for peace of mind. (Currently, there is a bug where Xtool hangs if an invalid file is specified.)

$ file ~/xtool/xcode.xip
/home/sevenc7c/xtool/xcode.xip: xar archive compressed TOC: 3942, SHA-1 checksum
  1. Install Xtool.
$ curl -fL \
    "https://github.com/xtool-org/xtool/releases/latest/download/xtool-$(uname -m).AppImage" \
    -o ./xtool
$ chmod +x ./xtool
$ mv ./xtool ~/.local/bin/xtool  # Anywhere is fine as long as it's in your PATH
  1. Log in with Xtool.
$ xtool setup

At this time, you can choose whether to log in using an API key or a password:

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):

To use an API key, you need to join the paid Apple Developer Program. If you are already a member, using this option is recommended.
If you are not a member, you will need to select the password option.

  1. Specify the path to Xcode.xip.
Choice (0-1): 1
...
Path to Xcode.xip: <path where you downloaded it in step 1>

After that, wait until it finishes extracting, and the setup will be complete.

3: Creating the App

  1. Create a project.
$ xtool new Hello
Creating package: Hello
Creating Package.swift
Creating xtool.yml
Creating .gitignore
Creating .sourcekit-lsp/config.json
Creating Sources/Hello/HelloApp.swift
Creating Sources/Hello/ContentView.swift

Finished generating project Hello. Next steps:
- Enter the directory with `cd Hello`
- Build and run with `xtool dev`

The app should be created under the Hello directory.

$ cd Hello
  1. Edit xtool.yml.
 version: 1
-bundleID: com.example.hello
+bundleID: com.sevenc7c.hello
  1. Edit the files under Sources/Hello as needed.

4: Installing the App

When using usbipd + usbmuxd

  1. Connect your iPhone/iPad device to your PC via USB.
  2. Open Command Prompt with administrator privileges.
  3. Obtain the busid.
> usbipd list
Connected:
BUSID  VID:PID    DEVICE                                                        STATE
2-2    0b05:19af  AURA LED Controller, USB 入力デバイス                         Not shared
2-3    046d:c077  USB 入力デバイス                                              Not shared
2-11   1132:4511  USB 大容量記憶装置                                            Not shared
2-14   8087:0026  インテル(R) ワイヤレス Bluetooth(R)                           Not shared
6-3    046d:c31d  USB 入力デバイス                                              Not shared
6-4    05ac:12a8  Apple Mobile Device USB Composite Device                      Not shared

Persisted:
GUID                                  DEVICE

Note down the BUSID for the "Apple Mobile Device USB Composite Device".

  1. Transfer the control of the iPhone/iPad to the WSL side.
! usbipd bind --busid <busid>
! usbipd attach --wsl --busid <busid>

In some cases, usbipd attach may fail with a "Device busy" error:

WSL usbip: error: Attach Request for 6-4 failed - Device busy (exported)

If that happens, it works well if you repeatedly run the following command (Up -> Enter) while reconnecting the USB:

! usbipd bind --busid <busid> --force && usbipd attach --wsl --busid <busid>

If successful, the iPhone/iPad should appear when running the following command:

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 006: ID 05ac:12a8 Apple, Inc. iPhone 5/5C/5S/6/SE/7/8/X/XR
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  1. Run xtool dev.
$ xtool dev

However, it did not work in my environment... (Related Issue)

For Sideloading Environments

  1. Build the ipa.
$ xtool dev build --ipa
Planning...
Building for debugging...
[8/8] Linking Hello-App
Build of product 'Hello-App' complete! (8.22s)
Packaging...
Wrote to /home/sevenc7c/xtool/Hello/xtool/Hello.ipa
  1. Install the ipa on your device.

Please refer to the documentation of the sideloading tool you are using.

If successful, the app should be sideloaded.

Conclusion

While I have only managed to build it so far, I think there is great significance in the fact that it could be built at all.
Since features like previews in Xcode are unavailable, it's likely more practical to use cross-platform GUI libraries such as Capacitor. (I haven't managed to get Capacitor running with Xtool yet...)

Thank you very much.

GitHubで編集を提案

Discussion