RxSwift: Error when using package manager in Xcode 11.4 beta

Short description of the issue:

I create new project for test using RxSwift via Swift package manager . In Xcode project I chose File -> Swift Packages -> Add Package Dependency... to add RxSwift repo. But after Xcode fetch the RxSwift lib successful. I press build and get the error:

ld: warning: Could not find or use auto-linked library 'XCTestSwiftSupport'
ld: warning: Could not find or use auto-linked framework 'XCTest'
Undefined symbols for architecture x86_64:
  "XCTest.XCTAssertEqual<A where A: Swift.Equatable>(_: @autoclosure () throws -> A, _: @autoclosure () throws -> A, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> ()", referenced from:
      RxTest.XCTAssertEqual<A where A: Swift.Equatable>(_: [RxSwift.Event<A>], _: [RxSwift.Event<A>], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
      RxTest.XCTAssertEqual<A where A: Swift.Equatable>(_: [RxSwift.SingleEvent<A>], _: [RxSwift.SingleEvent<A>], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
      RxTest.XCTAssertEqual<A where A: Swift.Equatable>(_: [RxSwift.MaybeEvent<A>], _: [RxSwift.MaybeEvent<A>], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
      RxTest.XCTAssertEqual(_: [RxSwift.CompletableEvent], _: [RxSwift.CompletableEvent], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
      RxTest.XCTAssertEqual<A where A: Swift.Equatable>(_: [RxTest.Recorded<RxSwift.Event<A>>], _: [RxTest.Recorded<RxSwift.Event<A>>], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
      RxTest.XCTAssertEqual<A where A: Swift.Equatable>(_: [RxTest.Recorded<RxSwift.Event<A?>>], _: [RxTest.Recorded<RxSwift.Event<A?>>], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
      RxTest.XCTAssertRecordedElements<A where A: Swift.Equatable>(_: [RxTest.Recorded<RxSwift.Event<A>>], _: [A], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
      ...
  "XCTest.XCTFail(_: Swift.String, file: Swift.StaticString, line: Swift.UInt) -> ()", referenced from:
      RxTest.XCTAssertRecordedElements<A where A: Swift.Equatable>(_: [RxTest.Recorded<RxSwift.Event<A>>], _: [A], file: Swift.StaticString, line: Swift.UInt) -> () in RxTest.o
  "__swift_FORCE_LOAD_$_XCTestSwiftSupport", referenced from:
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_RxTest in RxTest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Showing All Messages
Could not find or use auto-linked library 'XCTestSwiftSupport'

Could not find or use auto-linked framework 'XCTest'

Undefined symbol: XCTest.XCTAssertEqual<A where A: Swift.Equatable>(_: @autoclosure () throws -> A, _: @autoclosure () throws -> A, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> ()

Undefined symbol: XCTest.XCTFail(_: Swift.String, file: Swift.StaticString, line: Swift.UInt) -> ()

Undefined symbol: __swift_FORCE_LOAD_$_XCTestSwiftSupport

Expected outcome:

Expected run success.

What actually happens:

Got the error with above log

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

5.0.1

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

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

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

Xcode version:

Xcode 11.4 beta 1

⚠️ 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. ⚠️

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules
  • Swift Package Manager

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

  • yes (which ones)
  • 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
  • I have a significant code base

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 26 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@freak4pc Yes, for my project it work great. In build settings for main app in chapter build options I change Enable Testing Search Path from NO to YES. I think, that is allow to find path to XCTest framework and use necessary symbol.

@nhatlee @freak4pc Hello! I have completely translated my project to SPM and have this issue. In this attachment test project with RxSwift Libraries and working tests with static linking RxTest. Enable Testing Search Path with flag YES in this package configuration with additional wrapper local package allows you to run unit tests. RxTestProj.zip

The workaround is to wrap all of your Rx dependencies in one product inside your own app, which would remove the duplications. I’m not sure this would work for RxTest and RxBloccking, though:

let package = Package(
  name: "Rx Wrapper",
  products: [
    .library(name: "Rx", targets: ["Rx"]),
    .library(name: "RxTesting", targets: ["RxTesting"])
  ],
  dependencies: [
    .package(
      url: "https://github.com/ReactiveX/RxSwift.git",
      .upToNextMajor(from: "5.0.0")
    )
  ],
  targets: [
    .target(
      name: "Rx",
      dependencies: ["RxSwift" , "RxCocoa", "RxRelay"]
    ),
    .target(
      name: "RxTesting",
      dependencies: ["RxTest", "RxBlocking"]
    )
  ]

I’m not sure this will work for the test target, as mentioned above. This workaround was added in the SPM Slack by @DevAndArtist, but I hope Apple will provide an actual solution at some point:

RxSPM_Mod.zip

@antranapp From the tests I’ve ran it only solves half of the issues. Tests still don’t run.

There’s a long discussion in the SPM slack around this, and generally, it’s an “open bug” . What we might have to do is basically not allow installing RxTest and RxBlocking via SPM until Apple solves this, and that should mostly solve it, I believe.

In my project, Excluding the RxTest and RxBlocking parts of RxSwift solved the error.

From discussions in the SPM slack this seems like a bug. I’ve reported it here: https://bugs.swift.org/browse/SR-12303 And also filed a feedback: FB7608638

If someone gets error “Missing libXCTestSwiftSupport.dylib” after set Enable Testing Search Path than you must readd the library (package dependency) and set targets of RxTest and RxBlocking to your test targets. Look here to see the example.

In my project, Excluding the RxTest and RxBlocking parts of RxSwift solved the error.

Best answer if you wouldn’t use RxTest and RxBlocking in unit tests. It works perfectly for me.

That helps. Thank you! I’ll take a look.

In my project yes. RxDataSource, RxSwiftExt and RxGesture.

This is still an issue in Xcode 11.5. I’m not sure if there is much to be done here or if there is reason to leave this open. Apple provides us no way to make this work well. The only workable option would be to break RxSwift into a bunch of smaller repos (5-6-7 repos) which isn’t something I’m interested in doing. I hope they’ll find a fix for this soon.

If anyone has any additional questions / feedback, feel free to comment and I can always reopen. Thanks!

I have a similar problem now with Xcode 11.4.1

I can see now, if I integrate RxSwift using SPM, SPM will built RxSwift as a static library:

Screenshot 2020-05-06 at 22 04 31

I could workaround the issue by forcing SPM to build RxSwift as a dynamic framework in my fork: https://github.com/antranapp/RxSwift/commit/722615a926029289acd671dcf95a7494d41caf06

Screenshot 2020-05-06 at 22 05 07

Is there any reason that we are not building RxSwift as a dynamic library by default?

I have the same issue after updating to Xcode 11.4 (stable version, not beta). Any way to solve/workaround this?

After some trying. It seem the issue related to problem with linking XCTest. Move RxTest from target to testTarget fixed the issue. The change for Package file like this commit: https://github.com/nhatlee/RxSwift/commit/19df574ac70e4ce3f758a807b8541097c7397398