# Cannot use MusicKit with SwiftPM

**URL:** <https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570>\
**Category:** Using Swift\
**Tags:** packagemanager, musickit\
**Created:** [September 13, 2024, 2:41pm UTC](https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570 "2024-09-13T14:41:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayadamsmorgan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jayadamsmorgan/32/37274_2.png) [@jayadamsmorgan](https://forums.swift.org/u/jayadamsmorgan)\
**Post date:** [September 13, 2024, 2:41pm UTC](https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570/1 "2024-09-13T14:41:01Z")

</div>

This is probably not the place to ask this question, but I'm not sure where else to ask...  
I am building a CLI tool which would use MusicKit

`Package.swift`:

```swift
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Yatoro",
    dependencies: [
        .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
        .package(url: "https://github.com/apple/swift-log.git", from: "1.6.1"),
    ],
    targets: [
        .executableTarget(
            name: "Yatoro",
            dependencies: [
                .product(name: "ArgumentParser", package: "swift-argument-parser"),
                .product(name: "Logging", package: "swift-log"),
            ],
            linkerSettings: [
                .unsafeFlags([
                    "-Xlinker", "-sectcreate",
                    "-Xlinker", "__TEXT",
                    "-Xlinker", "__info_plist",
                    "-Xlinker", "Sources/Yatoro/Resources/Info.plist",
                ])
            ]
        ),
    ]
)

```

`Info.plist`:

```xml
<?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>CFBundleName</key>
    <string>Yatoro</string>
    <key>CFBundleIdentifier</key>
    <string>mybundleidentifier.yatoro</string>
    <key>NSAppleMusicUsageDescription</key>
    <string>This app requires access to Apple Music to play music tracks.</string>
</dict>
</plist>

```

I have found [this](https://forums.swift.org/t/swift-package-manager-use-of-info-plist-use-for-apps/6532/13) solution to include Info.plist into the SwiftPM build with the linker flags.

If I run it from Xcode the CLI app runs fine and I get the authorization prompt. But if I try to run Xcode built executable or the executable built with `swift build` from the command line it crashes on `MusicAuthotization.request()`.  
It's kind of frustrating, not really know when to look. Any advice?

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [September 13, 2024, 3:39pm UTC](https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570/2 "2024-09-13T15:39:12Z")

</div>

The short answer is you can't build it with `swift build` as that builds a pure Swift package where you'd need to declare it as a dependency in your Package.swift file but there's nothing to import (since it's not open source). The easiest thing is to just build in as an Xcode app

---

<div class="post-metadata">

**Author:** ![jayadamsmorgan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jayadamsmorgan/32/37274_2.png) [@jayadamsmorgan](https://forums.swift.org/u/jayadamsmorgan)\
**Post date:** [September 13, 2024, 3:52pm UTC](https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570/3 "2024-09-13T15:52:20Z")

</div>

Thanks! But how can I build it with an Xcode then to run the executable from terminal? The Xcode built executable is also crashing when I run it in the terminal

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [September 13, 2024, 3:54pm UTC](https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570/4 "2024-09-13T15:54:05Z")

</div>

You _should_ be able to get the binary created by Xcode and call that from the command line. (You can also set arguments by editing the scheme in Xcode for development). How to actually do that if the usual build and find the binary doesn't work I don't know I'm afraid as I'm a server dev! But the Apple Developer forums may be more useful for a question like that

---

<div class="post-metadata">

**Author:** ![jayadamsmorgan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jayadamsmorgan/32/37274_2.png) [@jayadamsmorgan](https://forums.swift.org/u/jayadamsmorgan)\
**Post date:** [September 13, 2024, 3:55pm UTC](https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570/5 "2024-09-13T15:55:58Z")

</div>

Thanks anyway, that was helpful!

---

<div class="post-metadata">

**Author:** ![jayadamsmorgan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jayadamsmorgan/32/37274_2.png) [@jayadamsmorgan](https://forums.swift.org/u/jayadamsmorgan)\
**Post date:** [September 14, 2024, 3:59pm UTC](https://forums.swift.org/t/cannot-use-musickit-with-swiftpm/74570/6 "2024-09-14T15:59:29Z")

</div>

UPD:  
Solved by manually adding terminals and the CLI app itself in `System Settings > Privacy & Security > Media & Apple Music`
