Swift组件混编依赖OC组件导致编译报错Abort trap: 6

问题现象

最近使用Swift与OC进行组件化开发时碰到一个问题,当满足以下条件时编译时报Abort trap: 6错误:

  1. Swift组件依赖于"DDBaseVC"OC组件。
  2. "DDBaseVC"组件依赖于"DDBaseKit"OC组件。
  3. 在Swift中同时import BaseVC和BaseKit组件。

会报以下错误:

<unknown>:0: error: fatal error encountered while reading from module 'DDGlobalSearchComponent'; please file a bug report with your project and the crash log

*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
top-level value not found
Cross-reference to module 'DDBaseVC'
... Ignore

Stack dump:
0.  Program arguments: 
...
1.  While generating Objective-C header
2.  While loading conformances for 'BaseCollectionController' (in module 'DDGlobalSearchComponent')
3.  While reading inherited conformance for type 'BaseCollectionController'
4.  While cross-referencing conformance for 'NSObject' (in module 'ObjectiveC')
0  swift                    0x00000001106e0ee3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x00000001106e06bc SignalHandler(int) + 348
2  libsystem_platform.dylib 0x00007fff79b1cb5d _sigtramp + 29
3  libsystem_platform.dylib 0x00007fd4f612b000 _sigtramp + 2086724800
4  libsystem_c.dylib        0x00007fff799dc6a6 abort + 127
5  swift                    0x000000010d860120 swift::ModuleFile::fatal(llvm::Error) + 1856
6  swift                    0x000000010d87b93f swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 4287
7  swift                    0x000000010d87b20a swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 2442
8  swift                    0x000000010d87e51b swift::ModuleFile::loadAllConformances(swift::Decl const*, unsigned long long, llvm::SmallVectorImpl<swift::ProtocolConformance*>&) + 315
9  swift                    0x000000010dafe352 swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage) + 1154
10 swift                    0x000000010dafe0f7 swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage) + 551
11 swift                    0x000000010dafdfaa swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage) + 218
12 swift                    0x000000010db02aa4 swift::ConformanceLookupTable::lookupConformances(swift::NominalTypeDecl*, swift::DeclContext*, swift::ConformanceLookupKind, llvm::SmallVectorImpl<swift::ProtocolDecl*>*, llvm::SmallVectorImpl<swift::ProtocolConformance*>*, llvm::SmallVectorImpl<swift::ConformanceDiagnostic>*) + 68
13 swift                    0x000000010c54f1e9 bool llvm::function_ref<bool (llvm::raw_pwrite_stream&)>::callback_fn<printAsObjCIfNeeded(llvm::StringRef, swift::ModuleDecl*, llvm::StringRef, bool)::$_7>(long, llvm::raw_pwrite_stream&) + 5145
14 swift                    0x000000010c55133a swift::withOutputFile(swift::DiagnosticEngine&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>) + 2602
15 swift                    0x000000010c54c8f3 emitAnyWholeModulePostTypeCheckSupplementaryOutputs(swift::CompilerInstance&, swift::CompilerInvocation&, bool) + 435
16 swift                    0x000000010c541ca1 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 36081
17 swift                    0x000000010c5356de swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862
18 swift                    0x000000010c4d37be main + 1246
19 libdyld.dylib            0x00007fff799373d5 start + 1
20 libdyld.dylib            0x00000000000000f0 start + 2255260956
error: Abort trap: 6

解决方法:

在Swift组件的.podspec文件中添加以下代码:

 s.pod_target_xcconfig = { 'SWIFT_COMPILATION_MODE' => 'wholemodule' }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述 利用runtime特性实现iOS项目的组件化开发,是由@casatwy大神提出来的,在他的博客中具体介绍...
    Mr杰杰阅读 1,640评论 2 9
  • 由于附近修路,今天家里停电一天,天气实在太热了,停电的日子怎么度过?没有空调,简直活不下去,在家过了一上午难熬的日...
    复明的瞎子阅读 350评论 0 0
  • 创业的哥们觉得要突破一步一步走的农民思维,要有超人的想法,才会在机遇到来之时有所突破。严谨的审计人员会觉得,上兵伐...
    新兴市场的小逻辑阅读 248评论 0 0
  • 光阴照晓,斜穿朱纱,明暗几支花。 书古香疏,影残山半,长天外几处人家。 欲作相思语,飞笺无处达。 叹只是落花,无人...
    沈绿萼阅读 127评论 0 0
  • 废话不多说,直接上代码 html js var file = document.getElementById('f...
    jia林阅读 912评论 4 0