由于 Catalyst ,最终可以将应用程序移植到 macOS了 ,问题是,许多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链接容器…
如果该库对于macOS而言不是至关重要的,但在iOS上仍然需要,那么最简单/最佳的做法是什么?
在@ajgryc回答之后,我能够做出一个光滑的解决方案:
在您的podfile中添加
post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "Pods-[Name of Project]" puts "Updating #{target.name} OTHER_LDFLAGS to OTHER_LDFLAGS[sdk=iphone*]" target.build_configurations.each do |config| xcconfig_path = config.base_configuration_reference.real_path xcconfig = File.read(xcconfig_path) new_xcconfig = xcconfig.sub('OTHER_LDFLAGS =', 'OTHER_LDFLAGS[sdk=iphone*] =') File.open(xcconfig_path, "w") { |file| file << new_xcconfig } end end end end
自可可足1.8.4
post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "Pods-[Name of Project]" puts "Updating #{target.name} to exclude Crashlytics/Fabric" target.build_configurations.each do |config| xcconfig_path = config.base_configuration_reference.real_path xcconfig = File.read(xcconfig_path) xcconfig.sub!('-framework "Crashlytics"', '') xcconfig.sub!('-framework "Fabric"', '') new_xcconfig = xcconfig + 'OTHER_LDFLAGS[sdk=iphone*] = -framework "Crashlytics" -framework "Fabric"' File.open(xcconfig_path, "w") { |file| file << new_xcconfig } end end end end
然后在Fabric的运行脚本构建阶段:
if [[$ARCHS != "x86_64"]]; then "${PODS_ROOT}/Fabric/run" [your usual key] fi