flutter项目编译ios的时候,在pod install报错

The following Swift pods cannot yet be integrated as static libraries

译:以下Swift pods还不能集成为静态库

我这里是集成firebase第三方库导致报错

上图报错信息

The Swift pod FirebaseCoreInternal depends upon GoogleUtilities, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries)use_modular_headers!:modular_headers => true

第一点,告诉我们导致报错的第三方库

第二点,我们可以添加use_modular_headers!来解决这个错误(全局)

第三点,我们可以添加 :modular_headers => true来解决错误(对应指定第三方库)

网上有很多大同小异的解决方法

例如:https://github.com/lottie-react-native/lottie-react-native/issues/784

他会告诉你在你的Podfile文件下添加use_frameworks! :linkage => :static 嘶~~~(倒吸一口凉气),这个use_frameworks! :linkage => :static怎么在上面没有提及呢。 嗯~~~, use_frameworks!、use_modular_headers!。那么这两者有什么区别呢? 在 Xcode 9 之前,不支持 Swift 静态库编译,因此 Swift pod 不得不使用动态库编译,即使用 use_frameworks!。但是,引用了大量动态库会导致应用程序启动时间变长。

在 Xcode 9 之后开始支持 Swift 静态库编译。从 CocoaPods 1.5.0 开始,对于 Swift pod,开发者不用必须在 Podfile 中指定 user_frameworks! 以强制使用动态库编译。不过,要注意的是,如果一个 Swift pod 依赖了一个 OC pod,那么我们要为对应的 OC pod 开启 modular headers(use_modular_headers! 就会开启 modular headers)。那么,Swift 引用 OC 时为什么要开启 modular headers?事实上,开启 modular headers 的本质就是将 pod 转换为 Modular(也就是支持模块),而 Modular 是可以直接在 Swift 中 import 的,不需要再经过 bridging-header 进行桥接,从而简化了 Swift 引用 OC 的方式。

只有支持了模块的框架,才能支持通过模块化头文件(Modular Header)的方式进行导入。Clang 支持模块编译,能够加速编译,减少出错。我们可以通过添加 modulemap 文件使框架支持模块。

简化 Swift 引用 OC 的方式是使用 use_modular_headers! 的一个原因,除此之外,use_modular_headers! 还能够解决一个历史原因。

在 CocoaPods 诞生之初,其致力于封装尽可能多的第三方库。为此,CocoaPods 使用了较为宽松的头文件搜索路径(Header Search Paths),允许 pod 之间的相互引用,无需考虑命名空间,不必采用 #import 的模块导入方式,允许采用 #import “fileName.h” 的导入方式。

但是,如果给 pod 添加 module map 使其支持模块化,会导致 #import “fileName.h” 无法正常导入。使用 use_modular_headers! 可以强制使用更优的模块导入方式。

在 CocoaPods 1.5.0 中,为了使用模块导入方式。对于 pod 开发者,可以在 pod_target_xxconfig 内设置 ‘DEFINES_MODULE’ => ‘YES’。对于 pod 使用者,可以在 Podfile 中添加 use_modular_headers! 指定采用模块导入的方式,也可以通过 :modular_headers => true 配置只让特定的 pod 采用模块导入的方式。

其实use_frameworks!、use_modular_headers!这两个我都不推荐使用,因为如果使用use_frameworks!、use_modular_headers!,会导致其他oc资源文件的丢失,如:.a文件,所以你不确定你是否有使用.a的第三方文件,还是乖乖用:modular_headers => true处理,当然,如果你确定没有.a文件,可以直接使用use_frameworks!。

正如上图报错第三方库The Swift pod FirebaseCoreInternal depends upon GoogleUtilities,那么就在FirebaseCoreInternal和GoogleUtilities添加上:modular_headers => true即可

在你的ios项目文件夹中找到Podfile文件,找到target配置

例:

pod ‘FirebaseCoreInternal’,‘9.2.0’, :modular_headers => true

pod ‘GoogleUtilities’,‘7.7.0’, :modular_headers => true

重新pod install即可

end

相关链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: