当前位置: 首页 > 工具软件 > Kingfisher > 使用案例 >

Xcode_xcode_13.0导入第三方组件Kingfisher报错解决

西门良才
2023-12-01
  • Debug模式下运行无错误、当切换为Release模式进行打包是会进行报错

报错提示大致如下,截取其中一段,均是由于SwiftUI导致

~/Merchant/Pods/Kingfisher/Sources/SwiftUI/ImageBinder.swift:51:23: error: cannot find type 'Binding' in scope
        var isLoaded: Binding<Bool>
                      ^~~~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/ImageBinder.swift:57:80: error: cannot find type 'Binding' in scope
        init(source: Source?, options: KingfisherOptionsInfo? = nil, isLoaded: Binding<Bool>) {
                                                                               ^~~~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/ImageBinder.swift:69:41: error: cannot find type 'Binding' in scope
        init(source: Source?, isLoaded: Binding<Bool>) {
                                        ^~~~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/ImageBinder.swift:110:56: error: cannot find 'Animation' in scope
                                    .map { duration in Animation.linear(duration: duration) }
                                                       ^~~~~~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/ImageBinder.swift:111:33: error: cannot find 'withAnimation' in scope
                                withAnimation(animation) { self.loaded = true }
                                ^~~~~~~~~~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/KFImage.swift:32:11: error: cannot find type 'Image' in scope
extension Image {
          ^~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/KFImage.swift:59:83: error: cannot find type 'Binding' in scope
    public init(source: Source?, options: KingfisherOptionsInfo? = nil, isLoaded: Binding<Bool> = .constant(false)) {
                                                                                  ^~~~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/KFImage.swift:75:72: error: cannot find type 'Binding' in scope
    init(_ url: URL?, options: KingfisherOptionsInfo? = nil, isLoaded: Binding<Bool> = .constant(false)) {
                                                                       ^~~~~~~
~/Merchant/Pods/Kingfisher/Sources/SwiftUI/KFImage.swift:85:44: error: cannot find type 'Binding' in scope
    public init(source: Source?, isLoaded: Binding<Bool> = .constant(false)) {
                                           ^~~~~~~
  • 解决方案:
    Podfile文件中添加以下函数,然后运行pod install
platform :ios, '11.0'
use_frameworks!
install! 'cocoapods', :disable_input_output_paths => true
inhibit_all_warnings!

flutter_application_path = '../../merchant_flutter/'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target 'Merchant' do
  
  pod 'Alamofire', '~> 5.4.3' #网络请求
  pod 'RxSwift', '~> 6.2.0' #响应式编程
  pod 'Kingfisher', '~> 6.3.0' #网络图片加载,SDWebImage的swift版本
  
  
  ## ==============Flutter ==============
  install_all_flutter_pods(flutter_application_path)
  ## ==============Flutter ==============
  
  post_install do |installer|
  	#调用移除函数
    remove_swift_ui()  
    installer.pods_project.targets.each do |target|
      #if target.name =="App" || target.name =="Flutter"
      target.build_configurations.each do |config|
        config.build_settings['ENABLE_BITCODE'] ='NO'
        config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = 'NO'
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
        
        #end
      end
    end
  end
end
# 添加以下函数
def remove_swift_ui
  system("rm -rf ./Pods/Kingfisher/Sources/SwiftUI")
  code_file = "./Pods/Kingfisher/Sources/General/KFOptionsSetter.swift"
  code_text = File.read(code_file)
  code_text.gsub!(/#if canImport\(SwiftUI\) \&\& canImport\(Combine\)(.|\n)+#endif/,'')
  system("rm -rf " + code_file)
  aFile = File.new(code_file, 'w+')
  aFile.syswrite(code_text)
  aFile.close()
end
 类似资料: