在更新Xcode14之后发现编译项目在iOS12.5以上的系统都正常,但是在跑iOS12.5以下的系统,例如iOS11,和iOS12.1之类的系统会报错,报错如下:
dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib
Referenced from: /private/var/containers/Bundle/Application/xxx-xxx-xxx-xxx-xxxx/xxx.app/Frameworks/xxx.framework/xxx
Reason: image not found
一看原因发现为image not found,但是项目中也没有用到这个库的image,而且在iOS12.5以上跑没有问题,所以显然不是这个问题,那么应该就是这个Library not loaded的问题。那么该问题的解决方案就是缺少那个library就在哪个库的 Targets-> Build Phase -> Link Binary with Libraries 中添加这个 libswiftCoreGraphics好了(报错是哪个库就加哪个)。例如我是缺少libswiftCoreGraphics,所以加一个libswiftCoreGraphics.tbd 就可以了;
注意还有一个前提:
那就是主工程中:Targets -> Build Settings ->Build Options -> Always Embed Swift Standard Libraries 需要设置为 Yes
方法二:(推荐方法) 在Podfile中统一修改
哪个库缺少就添加哪个库:
if target.name.eql?('库名')
libraries = config.build_settings['OTHER_LDFLAGS']
config.build_settings['OTHER_LDFLAGS'] = "#{libraries} -lswiftCoreGraphics"
libraryPath = config.build_settings['LIBRARY_SEARCH_PATHS']
config.build_settings['LIBRARY_SEARCH_PATHS'] = "#{libraryPath} $(SDKROOT)/usr/lib/swift"
end
与适配iOS16方法配合使用位置如下:(整体参考下面即可)
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
config.build_settings['CODE_SIGNING_required'] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
if target.name.eql?('库名')
libraries = config.build_settings['OTHER_LDFLAGS']
config.build_settings['OTHER_LDFLAGS'] = "#{libraries} -lswiftCoreGraphics"
libraryPath = config.build_settings['LIBRARY_SEARCH_PATHS']
config.build_settings['LIBRARY_SEARCH_PATHS'] = "#{libraryPath} $(SDKROOT)/usr/lib/swift"
end
end
end
end
方法三:对方法二的补充(如上述方法二还是会报错,可以使用以下方法)
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
config.build_settings['CODE_SIGNING_required'] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
if target.name.eql?('库名')
# Compose .xcconfig file path
configuration_file = "#{Dir.pwd}/Pods/Target Support Files/#{target.name}/#{target.name}.#{config}.xcconfig"
# Read values from the .xcconfig file
puts "#{target.name}.#{config}.xcconfig PATH #{configuration_file}"
libraries = read_xxconfig_Param(configuration_file,'OTHER_LDFLAGS')
libraryPath = read_xxconfig_Param(configuration_file,'LIBRARY_SEARCH_PATHS')
puts "#{target.name}.#{config}.xcconfig libraries #{libraries}"
config.build_settings['OTHER_LDFLAGS'] = "#{libraries} -lswiftCoreGraphics"
config.build_settings['LIBRARY_SEARCH_PATHS'] = "#{libraryPath} $(SDKROOT)/usr/lib/swift"
end
end
end
end
def read_xxconfig_Param(filePath,paramName)
paramValue = ""
if File::exist?(filePath)
IO.readlines(filePath).each do |block|
str = String.new(block)
if str.include? paramName
paramValue = str.gsub("#{paramName} = ","")
return paramValue
end
end
end
return ""
end