xcoderx-swiftswift-package-managerrx-cocoaswift-package

Unable to build a Swift package after adding the `RxSwift` package dependency: "product 'RxCocoa' not found"


I have created a new Swift package and trying to use the RxSwift dependency within it. I followed these instructions to add the dependency but my package is unable to build after this with the following error:

product 'RxCocoa' required by package 'mylibrary' target 'MyLibrary' not found.

My package manifest is here:

// swift-tools-version: 5.8
import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [them visible to other packages.
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    dependencies: [
        .package(url: "https://github.com/ReactiveX/RxSwift.git", .exact("6.5.0"))
    ],
    targets: [
        .target(
            name: "MyLibrary",
            dependencies: ["RxSwift", "RxCocoa"]),
        .testTarget(
            name: "MyLibraryTests",
            dependencies: ["MyLibrary"]),
    ]
)

enter image description here

I'm using Xcode 14.3. How should I add the RxSwift dependency to the package.


Solution

  • RxCocoa isn't its own package, it's a product in the RxSwift package. Your dependencies need to be set up like this:

    dependencies: [
        "RxSwift",
        .product(name: "RxCocoa", package: "RxSwift"),
    ]