Rxswift: "Missing Package Product" errors when using RxSwift 5.1.1 with SPM on Xcode 11.5

Created on 13 Jun 2020  路  2Comments  路  Source: ReactiveX/RxSwift

Short description of the issue:

When attempting to install RxSwift via SPM on Xcode 11.5, often times despite Xcode successfully cloning and checking out the RxSwift repo, the package doesn't resolve:

image

and attempting to compile leads to Missing Package Product errors:

image

Typically this isn't a huge issue because with some fiddling eventually in Xcode I can seem to get the package to resolve, however, this issue becomes problematic when doing CI builds, as it always fails on the initial command-line build. RxSwift is the only package this happens with, so I suspect it may have something to do with its SPM configuration. I'm curious if anyone has encountered any problems similar to this.

Expected outcome:
SPM package should reliably install every time

What actually happens:

The RxSwift package is checked out, but after package resolution finishes the package still isn't available.

Self-contained code example that reproduces the issue:

In my experience, this issue is caused by:

  1. Adding RxSwift has a project dependency via the SSH URL
  2. File > Swift Packages > Reset Package Caches
  3. Product > Clean Build Folder
  4. Build

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

5.1.1

Platform/Environment

  • [x] iOS
  • [x] macOS
  • [x] tvOS
  • [x] watchOS
  • [ ] playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • [ ] easy, 100% repro
  • [x] sometimes, 10%-100%
  • [ ] hard, 2% - 10%
  • [ ] extremely hard, %0 - 2%

Xcode version:

11.5 (11E608c)

:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:

Installation method:

  • [ ] CocoaPods
  • [ ] Carthage
  • [ ] Git submodules
  • [x] SPM

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • [ ] yes (which ones)
  • [x] no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • [ ] just starting
  • [ ] I have a small code base
  • [x] I have a significant code base

Most helpful comment

@freak4pc
Hello. I had the same problem a few days ago. I have tried to create my own package and set dependencies in Package.swift.
In case I had use:

let package = Package(
  name: "RxTestProject",
  dependencies: [
    .package(url: "https://github.com/ReactiveX/RxSwift.git", from: "5.0.0")
  ],
  targets: [
    .target(name: "RxTestProject", dependencies: ["RxSwift", "RxCocoa"])
  ]
)

Xcode haven't seen RxCocoa.
But I found the solution. I just set RxCocoa target dependencies as .product(name: "RxCocoa", package: "RxSwift"),
Package.swift:

let package = Package(
    name: "MyPackage", platforms: [.iOS(.v11)],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "MyPackage",
            targets: ["MyPackage"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/ReactiveX/RxSwift.git", from: "5.1.1"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "MyPackage",
            dependencies: ["RxSwift",
                           .product(name: "RxCocoa", package: "RxSwift")]),
    ]
)

Maybe it will be helpful for someone.

Swift Package Manager - Swift 5.2.0
Xcode 11.7

All 2 comments

Hey there :)
This is 99.9% an issue with SPM itself. In general, SPM has a critical bugs around repos like RxSwift and others that have dependencies that count on eachother (e.g. RxCocoa counts on RxSwift and RxRelay, RxTest counts on RxSwift, etc).

The SPM team knows this is an issue but haven't fixed it, yet. Unfortunately, we can't offer any support around this since it's not related to RxSwift itself, but to Apple's own lacking tooling which RxSwift and many other larger projects suffer from.

See #2127, #2050, #2100

@freak4pc
Hello. I had the same problem a few days ago. I have tried to create my own package and set dependencies in Package.swift.
In case I had use:

let package = Package(
  name: "RxTestProject",
  dependencies: [
    .package(url: "https://github.com/ReactiveX/RxSwift.git", from: "5.0.0")
  ],
  targets: [
    .target(name: "RxTestProject", dependencies: ["RxSwift", "RxCocoa"])
  ]
)

Xcode haven't seen RxCocoa.
But I found the solution. I just set RxCocoa target dependencies as .product(name: "RxCocoa", package: "RxSwift"),
Package.swift:

let package = Package(
    name: "MyPackage", platforms: [.iOS(.v11)],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "MyPackage",
            targets: ["MyPackage"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/ReactiveX/RxSwift.git", from: "5.1.1"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "MyPackage",
            dependencies: ["RxSwift",
                           .product(name: "RxCocoa", package: "RxSwift")]),
    ]
)

Maybe it will be helpful for someone.

Swift Package Manager - Swift 5.2.0
Xcode 11.7
Was this page helpful?
0 / 5 - 0 ratings

Related issues

apoloa picture apoloa  路  3Comments

kzaher picture kzaher  路  3Comments

RafaelPlantard picture RafaelPlantard  路  3Comments

jeremiegirault picture jeremiegirault  路  3Comments

Z-JaDe picture Z-JaDe  路  3Comments