swift - 不同项目中的 SPM 依赖关系
问题描述
我有两个项目的 iOS 工作区:
Core
- 是一个有框架的项目。它还RxSwift
通过 swift 包管理器具有依赖性。
App
- 是一个具有Core.framework
嵌入依赖项和RxSwift
swift 包管理器依赖项的应用程序。
我在应用程序运行时收到这些警告:
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
解决此崩溃的可能方法是什么?
解决方案
问题是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
模块内部使用。
推荐阅读
- mysql - 无法在 ubuntu 18.04 中导入 mysql 数据库
- postgresql - Postgres 登录问题
- django - 如何过滤显示在 django 表格中的数据?
- electron - 如何使用 electron-builder 仅构建 .app
- java - Servlet 从表单元素获取 NULL 参数
- javascript - 我正在尝试获得一种通用方法来等待加载 javascript 网页而不指定固定延迟
- django - 如何在 django rest 框架中自定义错误消息?
- google-apps-script - Google 脚本:使用 IMPORTDATA 公式更新单个单元格
- arrays - 删除 [String:[NSNumber]] 中匹配数字的键
- ssis - SSIS ADO.net 使用事务失败