Module not found error importing framework using SPM package

I'm trying to convert an existing project to use Swift Package Manager projects for its external dependencies. Previously I was using Carthage.


My project includes a private framework named HypnoLib, a share extension, and the main application. Both the share extension and the app depend on the private framework. The private framework depends on several SPM packages, one of which is named LlamaLib.


The private framework and the app build fine, but when I try to build the share extension I get these errors:


<module-includes>:2:9: note: in file included from <module-includes>:2:

#import "Headers/HypnoLib-Swift.h"

^

/Users/samalone/Library/Developer/Xcode/DerivedData/Succubus-ajafbtomyfjhlgbqdzjavilgugud/Build/Products/Debug-iphonesimulator/HypnoLib.framework/Headers/HypnoLib-Swift.h:185:9: error: module 'LlamaLib' not found

@import LlamaLib;

^

<unknown>:0: error: could not build Objective-C module 'HypnoLib'


Looking at the automatically generated file HypnoLib-Swift.h I see:


@import Foundation;
@import LlamaLib;


but I don't see imports for the other two SPM libraries that are used by HypnoLib.


So I guess my questions are:


  1. Why does HypnoLib-Swift.h try to import LlamaLib but not the other two SPM packages used in HypnoLib?
  2. Why can't LlamaLib be found when my share extension tries to import HypnoLib?

Replies

I am also having this issue.

Did you find the cause and solution for this?


EDIT: My current solution is to set SWIFT_INSTALL_OBJC_HEADER: NO, which skips generating swift header. We don't use our Swift code from ObjC, so so far this seems like a legit way.

I am experiencing the same issue. Turning off the auto-generated ObjC header "works" but doesn't seem like the right solution. I think the issue is one the swift package manager side in how it generates its compatibility. The issue for us seems to be Swift-only swift package, imported into Swift framework and used by something exposed to Objective C. This inserts the import in the compatibility header which causes issues.

Just ran into this (Swift module used in Objective-c Framework then used in Swift). Did you ever find a solution?

Found the solution, add:

-Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/<YourSwiftModuleImportedFromObjC>.modulemap

To Other Swift Flags.

  • Wow thank you for this, it totally works! I wonder why we needed to do this.

Add a Comment

Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/.modulemap

+1. Saved my days, thank you!