zoukankan      html  css  js  c++  java
  • flutter 基于oc的flutter项目使用基于swift的plugin导致报错问题

    flutter项目创建的时候ios项目使用的oc工程,在使用一个第三方plugin时报错各种关于swift的错误

    Xcode's output:
    ↳
        ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
        ld: warning: Could not find or use auto-linked library 'swiftDarwin'
        ld: warning: Could not find or use auto-linked library 'swiftUIKit'
        ld: warning: Could not find or use auto-linked library 'swiftFoundation'
        ld: warning: Could not find or use auto-linked library 'swiftCompatibility51'
        ld: warning: Could not find or use auto-linked library 'swiftMetal'
        ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
        ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
        ld: warning: Could not find or use auto-linked library 'swiftCompatibility50'
        ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
        ld: warning: Could not find or use auto-linked library
        'swiftCompatibilityDynamicReplacements'
        ld: warning: Could not find or use auto-linked library 'swiftDispatch'
        ld: warning: Could not find or use auto-linked library 'swiftCoreMedia'
        ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
        ld: warning: Could not find or use auto-linked library 'swiftCore'
        ld: warning: Could not find or use auto-linked library 'swiftCoreAudio'
        ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
        Undefined symbols for architecture x86_64:
          "value witness table for Builtin.UnknownObject", referenced from:
              full type metadata for kzcity_picker.SwiftKzcityPickerPlugin in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements", referenced from:
              __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant:
             __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_kzcity_picker)
          "__swift_FORCE_LOAD_$_swiftCompatibility51", referenced from:
              __swift_FORCE_LOAD_$_swiftCompatibility51_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibility51_$_kzcity_picker)
          "__swift_FORCE_LOAD_$_swiftCompatibility50", referenced from:
              __swift_FORCE_LOAD_$_swiftCompatibility50_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibility50_$_kzcity_picker)
          "__swift_FORCE_LOAD_$_swiftQuartzCore", referenced from:
              __swift_FORCE_LOAD_$_swiftQuartzCore_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftQuartzCore_$_kzcity_picker)
          "__swift_FORCE_LOAD_$_swiftCoreImage", referenced from:
              __swift_FORCE_LOAD_$_swiftCoreImage_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreImage_$_kzcity_picker)
          "__swift_FORCE_LOAD_$_swiftCoreGraphics", referenced from:
              __swift_FORCE_LOAD_$_swiftCoreGraphics_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreGraphics_$_kzcity_picker)
          "__swift_FORCE_LOAD_$_swiftCoreFoundation", referenced from:
              __swift_FORCE_LOAD_$_swiftCoreFoundation_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreFoundation_$_kzcity_picker)
          "_swift_getObjectType", referenced from:
              static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
              __C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftUIKit", referenced from:
              __swift_FORCE_LOAD_$_swiftUIKit_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftUIKit_$_kzcity_picker)
          "_swift_allocObject", referenced from:
              @objc kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "static (extension in
          Foundation):Swift.String._unconditionallyBridgeFromObjectiveC(__C.NSString?) ->
          Swift.String", referenced from:
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "_swift_getInitializedObjCClass", referenced from:
              type metadata accessor for __C.FlutterMethodChannel in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              type metadata accessor for kzcity_picker.SwiftKzcityPickerPlugin in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftFoundation", referenced from:
              __swift_FORCE_LOAD_$_swiftFoundation_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftFoundation_$_kzcity_picker)
          "__swift_FORCE_LOAD_$_swiftCoreAudio", referenced from:
              __swift_FORCE_LOAD_$_swiftCoreAudio_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreAudio_$_kzcity_picker)
          "static Swift.String.+ infix(Swift.String, Swift.String) -> Swift.String", referenced
          from:
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftDarwin", referenced from:
              __swift_FORCE_LOAD_$_swiftDarwin_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftDarwin_$_kzcity_picker)
          "_swift_unknownObjectRelease", referenced from:
              static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
              __C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              @nonobjc __C.FlutterMethodChannel.__allocating_init(name: Swift.String,
              binaryMessenger: __C.FlutterBinaryMessenger) -> __C.FlutterMethodChannel in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              @objc static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
              __C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              reabstraction thunk helper from @escaping @callee_unowned @convention(block)
              (@unowned Swift.AnyObject?) -> () to @escaping @callee_guaranteed (@in_guaranteed
              Any?) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftDispatch", referenced from:
              __swift_FORCE_LOAD_$_swiftDispatch_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftDispatch_$_kzcity_picker)
          "_swift_release", referenced from:
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              ___swift_destroy_boxed_opaque_existential_0 in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              @objc kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "_swift_deallocObject", referenced from:
              l_objectdestroy in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftMetal", referenced from:
              __swift_FORCE_LOAD_$_swiftMetal_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftMetal_$_kzcity_picker)
          "_swift_retain", referenced from:
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftObjectiveC", referenced from:
              __swift_FORCE_LOAD_$_swiftObjectiveC_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftObjectiveC_$_kzcity_picker)
          "_swift_unknownObjectRetain", referenced from:
              @objc static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
              __C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "Swift._bridgeAnythingToObjectiveC<A>(A) -> Swift.AnyObject", referenced from:
              reabstraction thunk helper from @escaping @callee_unowned @convention(block)
              (@unowned Swift.AnyObject?) -> () to @escaping @callee_guaranteed (@in_guaranteed
              Any?) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "_swift_getObjCClassMetadata", referenced from:
              type metadata accessor for __C.FlutterMethodChannel in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              @objc static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
              __C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "(extension in Foundation):Swift.String._bridgeToObjectiveC() -> __C.NSString",
          referenced from:
              @nonobjc __C.FlutterMethodChannel.__allocating_init(name: Swift.String,
              binaryMessenger: __C.FlutterBinaryMessenger) -> __C.FlutterMethodChannel in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "_swift_getObjCClassFromMetadata", referenced from:
              @nonobjc __C.FlutterMethodChannel.__allocating_init(name: Swift.String,
              binaryMessenger: __C.FlutterBinaryMessenger) -> __C.FlutterMethodChannel in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "__swift_FORCE_LOAD_$_swiftCoreMedia", referenced from:
              __swift_FORCE_LOAD_$_swiftCoreMedia_$_kzcity_picker in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
             (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreMedia_$_kzcity_picker)
          "type metadata for Swift.String", referenced from:
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "_swift_bridgeObjectRelease", referenced from:
              @nonobjc __C.FlutterMethodChannel.__allocating_init(name: Swift.String,
              binaryMessenger: __C.FlutterBinaryMessenger) -> __C.FlutterMethodChannel in
              libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
          "Swift.String.init(_builtinStringLiteral: Builtin.RawPointer, utf8CodeUnitCount:
          Builtin.Word, isASCII: Builtin.Int1) -> Swift.String", referenced from:
              static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
              __C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
              kzcity_picker.SwiftKzcityPickerPlugin.handle(_: __C.FlutterMethodCall, result:
              (Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
        ld: symbol(s) not found for architecture x86_64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    出现上面错误的原因是当前项目是oc项目,没有对swift的支持,通过添加swift版本和pod打包use_frameworks能够解决以上问题

    1.解决这个问题也很简单,进入到flutter工程中ios目录下,打开xcode项目

    Targets -> Build Settings->搜索左边的➕ -> Add User-Defined Setting -> 输入SWIFT_VERSION并设置swift版本为5.0[或者其他版本]
    

    2.找到Pofile文件并在 ttarget 'Runner' do 下添加 use_frameworks! 支持

    target 'Runner' do
      use_frameworks!
      flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    end
    

    操作完以上两步,重新执行flutter run 项目能正常跑起来了

  • 相关阅读:
    【09-04】java内部类学习笔记
    【09-03】java泛型学习笔记
    【08-23】redis学习笔记
    【06-23】js动画学习笔记01
    【11-23】mysql学习笔记02
    【06-18】CentOS使用笔记
    thinkphp+datatables+ajax 大量数据服务器端查询
    python遗传算法实现数据拟合
    简单的新闻客户端APP开发(DCloud+thinkphp+scrapy)
    python游戏编程——跟13岁儿童学编程
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/14034948.html
Copyright © 2011-2022 走看看