Anc*_*inu 5 ipad ios cocoapods swift mac-catalyst
由于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
Run Code Online (Sandbox Code Playgroud)
由于这是一个新话题,我找不到有关如何从macOS的构建中删除pod的文档,但如何在iOS和iPadO S上保留它。
可以在代码中使用:
#if !targetEnvironment(macCatalyst)
// Code to exclude for your macOS app
#endif
Run Code Online (Sandbox Code Playgroud)
但是问题的一部分,另一部分是仅针对iOS链接容器...
如果该库对于macOS而言并不重要,但仍在iOS上仍需要,那么最简单/最佳的做法是什么?
Oz *_*bat 23
对于处理 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
Run Code Online (Sandbox Code Playgroud)
Anc*_*inu 19
按照@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
Run Code Online (Sandbox Code Playgroud)
自 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
Run Code Online (Sandbox Code Playgroud)
然后在 Fabric 的运行脚本构建阶段:
if [[$ARCHS != "x86_64"]]; then
"${PODS_ROOT}/Fabric/run" [your usual key]
fi
Run Code Online (Sandbox Code Playgroud)
小智 13
打开项目 Pods 目录中的 Pods-$projectname.release.xcconfig 文件,并找到 OTHER_LDFLAGS 行。[sdk=iphone*]在变量名后立即添加(例如,我的现在看起来像这样):
OTHER_LDFLAGS[sdk=iphone*] = $(inherited) -ObjC -l"MailCore-ios" -l"c++" -l"iconv" -l"resolv" -l"xml2" -l"z"
Run Code Online (Sandbox Code Playgroud)
这仅在构建 iphone 变体时有条件地设置链接选项,防止 pod 在 OSX 上链接。当然,正如您所提到的,这需要与调用 pod 的代码结合#if !targetEnvironment(macCatalyst)并#endif包围它,否则您将收到链接器错误。
这让我解决了同样的问题。(如果您想知道除了条件变量之外还有哪些很酷的东西可以添加到 .xcconfig 文件中,这是我找到的参考:https ://pewpewthespells.com/blog/xcconfig_guide.html )
And*_*ndy 10
我有一个更新的解决方案,适用于以下 Google pod:
pod 'FirebaseUI/Auth'
pod 'FirebaseUI/Phone'
pod 'FirebaseUI/Email'
pod 'Firebase/Auth'
pod 'Firebase/Analytics'
pod 'Fabric', '~> 1.10.2'
pod 'Firebase/Crashlytics'
pod 'Firebase/AdMob'
Run Code Online (Sandbox Code Playgroud)
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name.start_with?("Pods")
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 "FirebaseAnalytics"', '')
xcconfig.sub!('-framework "FIRAnalyticsConnector"', '')
xcconfig.sub!('-framework "GoogleMobileAds"', '')
xcconfig.sub!('-framework "Google-Mobile-Ads-SDK"', '')
xcconfig.sub!('-framework "GoogleAppMeasurement"', '')
xcconfig.sub!('-framework "Fabric"', '')
new_xcconfig = xcconfig + 'OTHER_LDFLAGS[sdk=iphone*] = $(inherited) -framework "FirebaseAnalytics" -framework "FIRAnalyticsConnector" -framework "GoogleMobileAds" -framework "GoogleAppMeasurement" -framework "GoogleUtilities" "-AppMeasurement" -framework "Fabric"'
File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
使用 cocoapods 1.8.4,我不得不调整@AncAinu 的优秀答案如下:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
163 次 |
| 最近记录: |