xcode Swift 项目:导入模块化框架时“缺少必需的模块”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42085217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:46:27  来源:igfitidea点击:

Swift Project: "Missing Required Modules" when import a modular framework

iosswiftxcodeframeworksmodule-map

提问by HungCLo

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.modulemapto import CommonCrypto and Objective-C file into my swift framework.

    module.modulemap content: enter image description here

  1. 我创建了一个 swift 框架,其中包括 C 库(CommonCrypto)和一个 Objective C 文件。

  2. swift 项目中没有桥头文件。所以我创建了一个module.modulemap将 CommonCrypto 和 Objective-C 文件导入我的 swift 框架。

    module.modulemap 内容: 在此处输入图片说明

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

这是 module.modulemap 示例链接:Importing CommonCrypto in a swift framework

  1. In project settings, adding modulus.modulusmap path to swift compileenter image description here

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

    enter image description here

  1. 在项目设置中,添加modulus.modulusmap路径进行swift编译在此处输入图片说明

    所以,在我的 swift 框架中,一切正常。我可以像这样使用模数

    在此处输入图片说明

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 enter image description here

  3. Error occurs on this line when I use something inside the frameworkenter image description here

  1. 归档模块化框架并导出为内置产品。

  2. 在我的 swift 示例项目中,将模块化框架添加到 Embedded Binaries 在此处输入图片说明

  3. 当我在框架内使用某些东西时,这一行发生错误在此处输入图片说明

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'

  1. Swift 应用程序:导入导入静态库的框架时“缺少必需的模块”

  2. 将 RealmSwift 添加为子项目:缺少必需的模块:'Realm.Private'、'Realm'

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

有没有人对此有好的解决方案?谢谢!!

回答by HungCLo

Solution

解决方案

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

iOS 框架作为一个文件夹存在,创建一个module.modulemap来查找库或头文件。

  1. Setup module.modulemappath

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

  2. Add below to module.modulemap

  1. 设置module.modulemap路径

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

  2. 在下面添加到 module.modulemap

enter image description here

在此处输入图片说明

Remarks

评论

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

如果框架存档在同一开发环境中,则不必将 module.modulemap 添加到示例项目中。