首页 > 解决方案 > 使用催化剂移植到 mac 时排除 pod

问题描述

多亏了Catalyst,终于可以将应用程序移植到 mac,但问题是,许多 pod 不支持 AppKit。最常见的是 Crashlytics / Firebase。

In [...]/Pods/Crashlytics/iOS/Crashlytics.framework/Crashlytics(CLSInternalReport.o), building for Mac Catalyst, but linking in object file built for iOS Simulator, file '[...]/Pods/Crashlytics/iOS/Crashlytics.framework/Crashlytics' for architecture x86_64

由于这是一个最近的话题,我找不到关于如何从我的 macOS 构建中删除 pod 但保留它用于 iOS 和 iPadO S的文档。

可以在代码中使用:

#if !targetEnvironment(macCatalyst) 
// Code to exclude for your macOS app
#endif

但是问题的一部分,另一部分是仅针对 iOS 链接 pod ......

当库对 macOS 并不重要但在 iOS 上仍然需要时,最简单/最好的做法是什么?

标签: iosswiftipadcocoapodsmac-catalyst

解决方案


对于为 Catalyst 处理不受支持的框架的最佳方法,你们应该阅读Fernando Moya de Rivas的解决方案,他有一个 github,这里有一个包含更多最新信息的解决方案。

他基本上说你只需要定义一个你不想在mac osx上安装的所有库的数组,就像这样:['Fabric', 'Crashlytics', 'Firebase/Core', ...].

然后,您的 pod 文件看起来很简单:

# Podfile
load 'remove_unsupported_libraries.rb'

target 'My target' do
   use_frameworks!
   # Install your pods
   pod ...
end

# define unsupported pods
def catalyst_unsupported_pods
    ['Fabric', 'Crashlytics', 'Firebase/Core', ...]
end

# Remove unsupported pods from your project
post_install do |installer|   
    installer.configure_support_catalyst
end

推荐阅读