美文网首页
Swift组件混编依赖OC组件导致编译报错Abort trap:

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

作者: iamjjh | 来源:发表于2019-04-16 10:20 被阅读0次

    问题现象

    最近使用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' }
    

    相关文章

      网友评论

          本文标题:Swift组件混编依赖OC组件导致编译报错Abort trap:

          本文链接:https://www.haomeiwen.com/subject/iobpwqtx.html