Getting error "Cannot load underlying module" when importing Swift framework

3.6k Views Asked by At

I have written a framework in Swift 2.3 that uses Cocoapods to utilize a few Objective-C projects such as AFNetworking and CocoaLumberjack. Since bridging headers cannot be used in frameworks I have defined module maps for each Objective-C project (as well as for a few objective-c utiltities I have written). For example, the module.modulemap for AFNetworkModule looks like:

module AFNetworkModule {
  header "../../Pods/Headers/Public/AFNetworking/AFNetworkReachabilityManager.h"
  export *
}

Also added the path to modulemaps in the Build Settings -> Import Paths. This way I can import the modules in my framework swift code:

import AFNetworkModule

The setting Defines Module is set to Yes in the Build Settings for the framework.

Externally I can use the framework without any problems in my sample Swift app using import MyFramework when both the framework and the sample app are in the same workspace:

-- SampleAppProj
-- MyFrameworkProj
-- Pods

But I get "Cannot load underlying module for MyFramework" when trying to import the framework in a separate Swift project. The generated framework contains a Headers folder containing MyFramework-Swift.h and MyFramework.h (the umbrella file). I have not added any headers to the umbrella file as I am using modules to import objective-c internally in the swift framework.

1

There are 1 best solutions below

0
On

I had the same problem suddenly popping up regarding the AVFoundation module, on an app that was perfectly compiling till then. As a workaround, unchecking Show live issues in Xcode -> Settings -> General allows to avoid this error and to compile.

Edit: Adding the module to the project settings fixed the issue. See answers to this question.