Swift Project: “Missing Required Modules” when imp

2020-02-26 09:24发布

问题:

Setup

  1. I create a swift framework which include C library (CommonCrypto) and a Objective C file.

  2. There is no bridge-header in swift project. So I create a module.modulemap to import CommonCrypto and Objective-C file into my swift framework.

    module.modulemap content:

Here is the module.modulemap sample link:Importing CommonCrypto in a swift framework

  1. In project settings, adding modulus.modulusmap path to swift compile

    So, in my swift framework, everything works fine. I can use modulus like this

Problem shows

  1. Archive the modular framework and export as a built products.

  2. In my swift sample project, add modular framework to Embedded Binaries

  3. Error occurs on this line when I use something inside the framework

I have try so many solutions, but still not work.

Similar problems:

  1. Swift app: “Missing required module” when importing framework that imports static library

  2. Adding RealmSwift as a subproject: Missing required modules: 'Realm.Private', 'Realm'

Is anyone have a good solution for this? Thx!!

回答1:

Solution

iOS framework exists as a folder, create a module.modulemap to find out library or header file.

  1. Setup module.modulemap path

    In project/target/Build Settings/Swift Compile - Search Path/Import Path = “${SRCROOT}”

  2. Add below to module.modulemap

Remarks

You don't have to add module.modulemap to the sample project if the framework is archived on the same development environment.