使用催化剂移植到Mac时排除Pod [英] Exclude pod when porting to mac with catalyst
问题描述
借助 Catalyst ,终于可以将应用程序移植到Mac上了,问题是,许多Pod不支持AppKit. 最常见的一种是Crashlytics/Firebase.
Porting apps to mac is finally possible thanks to Catalyst, problem is, numerous pods don't support AppKit. Most common one would be 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.
Since it's a recent topic, I couldn't find doc on how to remove a pod from my build for macOS but keep it for iOS and iPadOS.
可以在代码中使用
#if !targetEnvironment(macCatalyst)
// Code to exclude for your macOS app
#endif
但这是问题的一部分,另一部分是仅针对iOS链接广告连播...
But that one part of the problem, the other part is to link the pod only for iOS...
如果库对于macOS而言并不重要,但在iOS上仍然需要,那么最简单/最佳的做法是什么?
What would be the easiest/best course of action when the library is not vital for macOS but still wanted on iOS?
推荐答案
在@ajgryc回答之后,我做出了一个流畅的解决方案:
Following @ajgryc answer, I was able to make a sleek solution:
在您的Podfile中添加
In your podfile add
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
自Cocoapods 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的运行脚本构建阶段:
And then in run script build phase for Fabric:
if [[$ARCHS != "x86_64"]]; then
"${PODS_ROOT}/Fabric/run" [your usual key]
fi
这篇关于使用催化剂移植到Mac时排除Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!