解决:Definition of 'AnyPromise' must be imported from module 'xxx' before it is required
in 技术 with 0 comment

解决:Definition of 'AnyPromise' must be imported from module 'xxx' before it is required

in 技术 with 0 comment

前言

当前只知道解决办法,至于具体的错误引起的原因还待考究,最重要的一个就是比如为什么 AnyPromise 必须从模块 xxx 中导入?后续若能解透再来补充。

问题

在创建私有 pod 库的时候,在.podspec中依赖了 PromiseKit 库:

s.dependency "PromiseKit/CorePromise", "~> 6.8"

然后在 xxx.h 文件中引入了 PromiseKit:

#import <PromiseKit/PromiseKit.h>

最后在运行 Example 项目,则会得到如下错误:

Definition of 'AnyPromise' must be imported from module 'xxx' before it is required

其中最重要的一点是,我为了提高 APP 启动速度,Example 项目的 Podfile 加入了静态库打包配置,所以才会造成上述问题:

use_modular_headers!

解决

找到上述报错的 xxx 类文件,把 #import <PromiseKit/PromiseKit.h> 替换为 @import PromiseKit。在其它地方使用,也建议采用 @import的引入方式。
另外由于 PromiseKit 是 Swift 库的缘故,需要在项目中新增 xxx_Example-Bridging-Header.h 文件。

Responses