Short description of the issue:
When RxCocoa is used in a project in Xcode 11, and it is imported as RxSwift package, unit tests for that project do not build, with following error:
missing required module 'RxCocoaRuntime'
I am not an expert on Swift Packages, just starting with it. I see RxCocoaRuntime is declared as a target in Package.swift, and RxCocoa depends on it. But it is not declared as a product.
This may be also Xcode's issue. But I don't have issues with other dependencies.
Expected outcome:
Tests build and are executed.
What actually happens:
Build fails.
Self contained code example that reproduces the issue:
Sample, minimal project: https://github.com/michallaskowski/RxCocoaTestsIssue
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
Current master, commit 6b2a406
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
Xcode 11 beta 7, tested also with beta 6
: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:
other - Swift Packages :)
I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)
Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)
I created a fork of RxSwift, and declared RxCocoaRuntime as a product/library. Linking RxCocoaRuntime with test targets makes it possible to build the target. But tests do not get launched, it seems RxSwift symbols are included in both host app, and test target because RxCocoaRuntime depends on RxSwift. Then the process stops with EXC_BAD_ACCESS.
The same happens when RxCocoa is not imported and tests build, but RxTest or RxBlocking is linked with test target.
This may be Swift Packages issue.
Also troubled by this problem 💔
Have you found any solution to this ? @michallaskowski
Xcode 11 GM, problem still exists.
UPDATE:
with GM Seed 2 does not work too
Happy to accept a PR around this if anyone's interested to investigate. I'll only have time in a a week or two.
I tried to reproduce duplicated symbols issue with a separate, small project. But SPM had no issues with it. I am not sure yet what triggers it for RxSwift, but also had not enough time to dig into it.
I have the same problem with the SPM and XCode 11. I investigated a bit, but I couldn’t solve it.
I think, there are two problems: One with the RxCocoaRuntime, that is not found. And the other, that RxBlocking/RxTest depend also on RxSwift. Therefore the test target contains the RxSwift symbols twice and crashes.
At the moment, I use Carthage for my dependencies. For the test target I don’t link the binary with libraries, I only add the path to the frameworks build by Carthage to “Runpath Search Paths“ and “Framework Search Paths” in the build settings. I tried to add the paths, where SPM builds the dependencies, but this didn’t solve the problem. Probably, because SPM doesn’t build “.framework” files.
I think, the dependencies between the RxSwift targets need to be declared differently, that SPM works also for the test targets.
I have same problem with XCode 11 with spm, but im only getting this error when including RxSwift in a iOS intents extension.
Anyone tested with Xcode 11.1?
https://developer.apple.com/documentation/xcode_release_notes/xcode_11_1_release_notes/
Same issue here with Xcode 11.0 (11A420a). Is anyone fixing it?
I'm not sure if it's the same case for everyone. But in my case, when I add "RxCocoa" to "Link Binary with Libraries" in the test target's Build Phase tab, it successfully built.
I have found out that it is a known issue with rdar://problem/54587458.
Work around is to add flag to explicitly append modulemap to the OTHER_SWIFT_FLAGS in the test target:
-Xcc -fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps/iphonesimulator/RxCocoaRuntime.modulemap
@achernoprudov where did you find a reference to that radar ?
@freak4pc I found it in swift-nio library. Issue-1228
I tested the changes, thanks for the info. While the tests build now, they are crashing on Xcodes 11.0, 11.1 GM, and 11.2 beta. On Xcode 11.1, swift_checkMetadataState throws EXC_BAD_ACCESS.
May be still an issue with Swift Packages, not RxSwift itself.
Sample project updated: https://github.com/michallaskowski/RxCocoaTestsIssue
I had that crash as well and fixed it by not adding a swift package dependency that isn't a dynamic library multiple times on different targets.
Well, yes. Removing RxTest and RxBlocking from test target stops the crash. But also doesn't solve anything, if I want to test reactive parts of code. Unless you mean something else in this case, @FabianTerhorst ?
RxTest and RxBlocking both depend on RxSwift target, which is linked in the host application.
Because of that, test target seems to also link RxSwift.
Potential fix is linking RxTest and RxBlocking to the host application, but well, it is not a great solution.
I don't have time to test this but seems to me the best way would be adding the flags @achernoprudov mentioned above using SPM's unsafeFlag.
More info:
I was able to get my tests to run by setting up the flag @achernoprudov mentioned
-Xcc -fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps/iphonesimulator/RxCocoaRuntime.modulemap
Also by adding the 5 frameworks from RXSwift directly to my main target only and removing them all from my test target.
Main Target

Test Target

May be still an issue with Swift Packages, not RxSwift itself.
I have the swift_checkMetadataState crash with only RxSwift dependency using CocoaPods in a sample project

@iwheelbuy you have crash because RxSwift is imported twice as static library. You have three solutions:
pod__Rx from TestTargetCrashTests.use_frameworks! for Pods that makes RxSwift dynamic.@achernoprudov I'd love to go the 2nd way, but how do I use RxSwift in the test target?
If I try to import RxSwift:
import XCTest
@testable import TestTargetCrash
import RxSwift
I got Cannot load underlying module for 'RxSwift' error.
If I try not to import RxSwift and start using Observables:
_ = Observable<Int>.just(1)
I got the Use of unresolved identifier 'Observable' error
Edit:
I decided to remove Allow testing Host Application APIs flag. Now test target is an independent one and everything works as expected.
May be still an issue with Swift Packages, not RxSwift itself.
I have the
swift_checkMetadataStatecrash with only RxSwift dependency using CocoaPods in a sample project
@iwheelbuy my project have the same problem. I download you sample code and remove Allow testing Host Application APIs flag but still crash. what can i do to fix it?
Can anyone confirm if this is working in Xcode 11.3 or its still a valid issue? Thanks !
Not working for me in Xcode 11.3.1 (that is, I cannot run tests, get the EXC_BAD_ACCESS error, when test target includes RxBlocking)
I think this is causing my test crashes in Xcode 11.3.1 as well, EXC_BAD_ACCESS and SIGABRT due to fatalError. XXX.app (51242) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying error: Crash: XXX (51242): type metadata completion function for CombineLatestSink2_))
Also, lots of console messages like:
objc[66240]: Class _TtC7RxSwift28SerialDispatchQueueScheduler is implemented in both /Users/kevin/Library/Developer/CoreSimulator/Devices/526603CF-6176-4EE4-9FD0-E8C2C6A37A8A/data/Containers/Bundle/Application/DB37749E-5C18-4EEE-AF65-038E9424A9D4/App.app/App (0x104811758) and /Users/kevin/Library/Developer/Xcode/DerivedData/App-amlfdpqbdiuhnsdxncuoocmqdrwl/Build/Products/Debug-iphonesimulator/App.app/PlugIns/AppTests.xctest/AppTests (0x1062b8e28). One of the two will be used. Which one is undefined.
....which I suspect is the problem: RxSwift is static in both the test and the app.
Since my unit tests don't use the UI, I just made them logic tests for now, so they're isolated from the app and don't have duplicate symbols with it.
Hey both. I'm sorry you're having this issue, but as far as I can tell, this is entirely an SPM problem (or it would happen in other package managers, or without one). I suggest filing a repoducible bug at bugs.swift.org and reference this thread, as well.
Thanks !
Thanks. I just set up an RxDataSources project to show the problem, and sent feedback to Apple, since for me, even if I say in a fork that RxSwift is dynamic, it's also including it as static.
Thanks, mind sharing the link here?
I suggest having one in bugs.swift.org specifically as it seems SPM-specific. Feedback would take longer to get noticed IMO
I was able to get my tests to run by setting up the flag @achernoprudov mentioned
-Xcc -fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps/iphonesimulator/RxCocoaRuntime.modulemapAlso by adding the 5 frameworks from RXSwift directly to my main target only and removing them all from my test target.
Main Target
Test Target
@AJBeltran3 how did you solve the main app crashing at startup with rxswift dyld: Library not loaded: @rpath/XCTest.framework/XCTest that happens when you include RXBlocking and RxTests to the main app?
@yusuke024
I'm not sure if it's the same case for everyone. But in my case, when I add "RxCocoa" to "Link Binary with Libraries" in the test target's Build Phase tab, it successfully built.
I'm here from google, tried to resolve another, but a similar bug. When I use Swift Package Manager and set "Host Application" to None for test target's settings, test target stops building with linking issues of SPM's dependencies. So I need to explicitly add those dependencies to test target's both Dependencies and Link Binary With Libraries sections in Build Phases tab. Thanks for suggestion!

I installed RxCocoa using Carthage in an empty iOS app target, and I see the same issue when I try to import RxCocoa: Missing required module 'RxCocoaRuntime'.
Xcode 11.5. Carthage 0.34 (latest). RxSwift 5.1.1.
Update: "Clean Build" helped. I initially installed the dependencies using SPM, and then replaced them with frameworks built by Carthage. Somehow, Xcode got confused.
Uhm, I just tried it in Carthage and it worked fine. Could you provide a repro project? @kean
Saw your comment. Thanks for the update. I'll be closing this for now.
IRT SPM specifically, see https://github.com/ReactiveX/RxSwift/issues/2127#issuecomment-643647705
The path to modulemap file has changed in Xcode 12, the OTHER_SWIFT_FLAGS flag should be like this:
-fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps-iphonesimulator/RxCocoaRuntime.modulemap
@RinatAbidullin Are you positive? If yes, it's worth filing an SPM bug.
Hi all for those of us just joining the party, what's the latest solution to this? i see some compiler flag (that maybe doesn't work?), I see a screenshot recommending adding the dependency manually to the test target, etc. Is this documented somewhere? Thanks!
Hey Gal 👋
There was a suggestion here but I haven't tested it personally. I've been hopeful Apple will fix up their mess but this doesn't seem to be the case.
https://github.com/ReactiveX/RxSwift/issues/2127#issuecomment-717830502
The path to modulemap file has changed in Xcode 12, the
OTHER_SWIFT_FLAGSflag should be like this:
-fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps-iphonesimulator/RxCocoaRuntime.modulemap
Depending on what you are building for (simulator, device, archive build) the modulemap path will reference the iphoneos platform and not iphonesimulator. Below is the flag I am using so the path is referencing the current platform:
-fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps-$(PLATFORM_NAME)/RxCocoaRuntime.modulemap
Most helpful comment
I have found out that it is a known issue with rdar://problem/54587458.
Work around is to add flag to explicitly append modulemap to the
OTHER_SWIFT_FLAGSin the test target: