首页 > 解决方案 > 不同项目中的 SPM 依赖关系

问题描述

我有两个项目的 iOS 工作区:

Core- 是一个有框架的项目。它还RxSwift通过 swift 包管理器具有依赖性。

App- 是一个具有Core.framework嵌入依赖项和RxSwiftswift 包管理器依赖项的应用程序。

我在应用程序运行时收到这些警告:

objc[8296]: Class _TtC7RxSwiftP33_AB3B9E8806A71B46FB498A7594F5E0D919AnonymousDisposable is implemented in both /Users/andrey/Library/Developer/Xcode/DerivedData/App-dypyskhwoifkwagjjvtjblqppdnd/Build/Products/Debug-iphonesimulator/Core.framework/Core (0x10e092400) and /Users/andrey/Library/Developer/CoreSimulator/Devices/53D234F9-F917-46BA-B376-F28BA905EE9D/data/Containers/Bundle/Application/D4C69694-8515-44CF-B077-0CB3256D1F84/App.app/App (0x10bf95430). One of the two will be used. Which one is undefined.

但是,如果我尝试访问MainScheduler.instance它是一个静态变量,我将EXC_BAD_ACCESS与堆栈崩溃:

#0  0x000000010e7d5c07 in swift_checkMetadataState ()
#1  0x000000010e7d9a17 in checkTransitiveCompleteness(swift::TargetMetadata<swift::InProcess> const*)::$_18::operator()(swift::TargetMetadata<swift::InProcess> const*) const ()
#2  0x000000010e7d97ac in bool findAnyTransitiveMetadata<checkTransitiveCompleteness(swift::TargetMetadata<swift::InProcess> const*)::$_18&>(swift::TargetMetadata<swift::InProcess> const*, checkTransitiveCompleteness(swift::TargetMetadata<swift::InProcess> const*)::$_18&) ()
#3  0x000000010e7d96a6 in checkTransitiveCompleteness(swift::TargetMetadata<swift::InProcess> const*) ()
#4  0x000000010e7da278 in swift::MetadataCacheEntryBase<(anonymous namespace)::SingletonMetadataCacheEntry, int>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) ()
#5  0x000000010e7d0078 in swift_getSingletonMetadata ()
#6  0x000000010b3bb9b8 in type metadata accessor for MainScheduler ()
#7  0x000000010af4b1c5 in static RxSchedulers.mainScheduler.getter 

解决此崩溃的可能方法是什么?

标签: swiftxcodeswift-package-manager

解决方案


问题是App模块有两个RxSwift相互冲突的依赖项。第一个是传递依赖,Core.framework第二个是App模块内部。它会导致此崩溃。

另一个表明您有两个相同依赖项问题的迹象可能是应用程序启动时的警告。像这个:

objc[8296]: Class _TtC7RxSwiftP33_AB3B9E8806A71B46FB498A7594F5E0D919AnonymousDisposable is implemented in both /Users/andrey/Library/Developer/Xcode/DerivedData/App-dypyskhwoifkwagjjvtjblqppdnd/Build/Products/Debug-iphonesimulator/Core.framework/Core (0x10e092400) and /Users/andrey/Library/Developer/CoreSimulator/Devices/53D234F9-F917-46BA-B376-F28BA905EE9D/data/Containers/Bundle/Application/D4C69694-8515-44CF-B077-0CB3256D1F84/App.app/App (0x10bf95430). One of the two will be used. Which one is undefined.

对于这种情况,可能的解决方法是从模块中删除RxSwift依赖项。App它不会破坏代码,因为RxSwift它是传递依赖,并且可以在App模块内部使用。


推荐阅读