xcodeswift-package-managercommand-line-tool

Can't run command line tool created with SPM from Xcode


I've created a command line tool using SPM. (I also added swift-argument-parser the project.)

I can open the package.swift file and Xcode opens a simulated project that lets me view, edit, and build the project.

I can then run the project from the command line using swift run <packagename> However, when I try to run the project from Xcode, I get an error "Failed to install the app on the device."

I've done this in the past, but don't remember what I needed to do to make it work. (It lets me source-level debug the command line tool, which is quite useful.) I can't get it to run now however. What do I need to do in order to be able to build and run my tool from Xcode?

The project is a shell at this point, and is essentially a minimal reproducible example. You can download it here: AsyncTest project on Github

When I click "View details" on the error alert, it says:

Failed to install the app on the device.
Domain: com.apple.dt.CoreDeviceError
Code: 3002
User Info: {
    DVTErrorCreationDateKey = "2024-01-17 20:32:33 +0000";
    IDERunOperationFailingWorker = IDEInstallCoreDeviceWorker;
    NSURL = "file:///Users/duncan/Library/Developer/Xcode/DerivedData/AsyncTest-ckvucgfbzimivdchumrrsvcsgaqj/Build/Products/Debug-iphoneos/AsyncTest";
}
--
The item at AsyncTest is not a valid bundle.
Domain: com.apple.dt.CoreDeviceError
Code: 3000
Failure Reason: Failed to read the bundle.
User Info: {
    NSURL = "file:///Users/duncan/Library/Developer/Xcode/DerivedData/AsyncTest-ckvucgfbzimivdchumrrsvcsgaqj/Build/Products/Debug-iphoneos/AsyncTest";
}

Solution

  • Ok, I figured it out. The scheme was set up to try to run the tool on my iPhone. I have no idea why, since command line tools are not valid for iOS, and I never asked to do anything with iOS.

    Once I select "My Mac" as the target it works.

    If you see this error on a command line tool from Xcode, this is the likely cause.