Search code examples
iosswiftxcodesentryswift-package-manager

Swift package product not found when added via Package.swift dependency


I'm trying to integrate the Sentry iOS SDK via Swift Package Manager. They provide a guide here, which is mainly tailored to those integrating with an Xcode project.

I'm integrating with a standalone Swift library package, which would rely on the Sentry package as a dependency. As such, my package dependencies are defined in my library's Package.swift file. When adding the Sentry package as a dependency, the package is resolved but the product is not. The package shows in the sidebar and I can view it's files, including it's Package.swift, so it's definitely being resolved/downloaded.

If I open a new Xcode project and add the package via 'Add Package Dependencies', it works just fine with the products resolved as well, which can be imported and used without issue, so the issue seems to be specifically with using Package.swift based dependency management.

The Sentry Package.swift is here. My library's Package.swift is below. Everything has been done correctly from what I and my colleagues can tell, we think there is potentially an SPM bug here.

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

import PackageDescription

let package = Package(
    name: "MyPackage",
    platforms: [
        .iOS(.v15)
    ],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "MyPackage",
            targets: ["MyPackage"]),
    ],
    dependencies: [
        .package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.24.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "MyPackage",
            dependencies: ["Sentry"]),
        .testTarget(
            name: "MyPackageTests",
            dependencies: ["MyPackage"]),
    ]
)

Can anyone offer any insight? Thanks.


Solution

  • I was able to get the dependencies to resolve and add import Sentry by changing the dependency on the target to

    .target(
        name: "MyPackage",
        dependencies: [.product(name: "Sentry", package: "sentry-cocoa")]),
    
    

    I think the issue might be something to do with the package actually being called sentry-cocoa, not Sentry. I'm not sure if that's exactly the issue, but using your package.swift didn't work but using mine did.

    Note that, after the change, I had to recalculate the package dependencies and clean the build folder to get rid of a load of cached nonsense.