Flutter导入flutter_video_compress遇到的问题

flutter_video_compress 是Flutter的一个视频压缩插件,用swift实现的,在导入过程中,出现了不少问题,在这里记录起来。

报错1:Undefined symbol: OBJC_CLASS$_BMKLocationManager

根据import插件的步骤,在profile文件设置 use_frameworks! ,Xcode build 之后出现这个报错:

Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_BMKLocationManager", referenced from:
      objc-class-ref in FlutterBaiduMapPlugin.o
  "_OBJC_CLASS_$_BMKLocationAuth", referenced from:
      objc-class-ref in FlutterBaiduMapPlugin.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Showing All Messages
:-1: Undefined symbol: _OBJC_CLASS_$_BMKLocationManager

Showing All Messages
:-1: Undefined symbol: _OBJC_CLASS_$_BMKLocationAuth

BMKLocationManager 是百度地图定位插件,一开始以为是这个插件不支持swift,找了很久原因,后面尝试不导入 flutter_video_compress,开启 use_frameworks!,百度定位的插件也没有报错,问题还是出在flutter_video_compress 插件上。

解决方法:有时候 pod install ,旧插件没有完全删除,会出现很多奇怪问题,彻底删除 pod 并重新 install是个好方法:

  • 删除iOS目录下 PodsApp名.xcworkspace目录 和 Podfile.lock文件:
    image.png
  • ios路径下执行:
pod install --verbose --no-repo-update
报错2:Regift.swift:251:45: Missing argument label 'preferredTimescale

确定重新 pod install 后,Xcode build 的时候又出现新的问题:

项目路径/ios/Pods/Regift/Regift/Regift.swift:251:45: Missing argument label 'preferredTimescale:' in call

有几个地方的代码出现报错,双击报错的地方,下面都有个 fix 按钮,点击之后代码的报错消失。

方法来源:https://github.com/flutter/flutter/issues/37447#issuecomment-518478400

报错3:Undefined symbol: protocol descriptor for Swift.Error

继续 build ,出现一大堆 swift 报错,吓了我一跳,还以为
上面的处理有问题,继续找解决方法:

Showing All Messages
:-1: Could not find auto-linked library 'swiftCoreFoundation'

:-1: Could not find auto-linked library 'swiftSwiftOnoneSupport'

:-1: Could not find auto-linked library 'swiftCore'

:-1: Could not find auto-linked library 'swiftQuartzCore'

:-1: Could not find auto-linked library 'swiftCoreGraphics'

:-1: Could not find auto-linked library 'swiftUIKit'

:-1: Could not find auto-linked library 'swiftDarwin'

:-1: Could not find auto-linked library 'swiftFoundation'

:-1: Could not find auto-linked library 'swiftsimd'

:-1: Could not find auto-linked library 'swiftObjectiveC'

:-1: Could not find auto-linked library 'swiftMetal'

:-1: Could not find auto-linked library 'swiftDispatch'

:-1: Could not find auto-linked library 'swiftCoreMedia'

:-1: Could not find auto-linked library 'swiftAVFoundation'

:-1: Could not find auto-linked library 'swiftCoreImage'

:-1: Could not find auto-linked library 'swiftCoreAudio'

:-1: Undefined symbol: protocol conformance descriptor for Swift.Int : Swift._ObjectiveCBridgeable in Foundation

:-1: Undefined symbol: protocol descriptor for Swift.Error

:-1: Undefined symbol: protocol conformance descriptor for Swift.Int : Swift.BinaryInteger in Swift

:-1: Undefined symbol: protocol conformance descriptor for Swift.Int32 : Swift.SignedInteger in Swift

:-1: Undefined symbol: protocol conformance descriptor for Swift.Int32 : Swift.FixedWidthInteger in Swift

:-1: Undefined symbol: protocol conformance descriptor for CoreGraphics.CGFloat : Swift.SignedNumeric in CoreGraphics

:-1: Undefined symbol: protocol conformance descriptor for CoreGraphics.CGFloat : Swift.Comparable in CoreGraphics

:-1: Undefined symbol: _swift_getTupleTypeMetadata2

:-1: Undefined symbol: Swift.Float.init(Swift.Float) -> Swift.Float

:-1: Undefined symbol: _swift_projectBox

:-1: Undefined symbol: Foundation.URL.pathExtension.getter : Swift.String

:-1: Undefined symbol: (extension in Foundation):__C.NSNumber.init(integerLiteral: Swift.Int) -> __C.NSNumber

:-1: Undefined symbol: static (extension in ObjectiveC):__C.NSObject.== infix(__C.NSObject, __C.NSObject) -> Swift.Bool

:-1: Undefined symbol: type metadata for Swift.Float

:-1: Undefined symbol: protocol witness table for Swift.Float : Swift.TextOutputStreamable in Swift

:-1: Undefined symbol: Swift.Dictionary.init(dictionaryLiteral: (A, B)...) -> [A : B]

:-1: Undefined symbol: Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> ()

:-1: Undefined symbol: type metadata for Foundation.Data

:-1: Undefined symbol: type metadata for Swift.Double

:-1: Undefined symbol: Swift.Dictionary.subscript.getter : (A) -> B?

:-1: Undefined symbol: static Swift.String.== infix(Swift.String, Swift.String) -> Swift.Bool

:-1: Undefined symbol: type metadata for Swift.Bool

:-1: Undefined symbol: Swift.String.init(describing: A) -> Swift.String

:-1: Undefined symbol: _swift_beginAccess

:-1: Undefined symbol: _swift_deallocObject

:-1: Undefined symbol: value witness table for Builtin.Int64

:-1: Undefined symbol: protocol descriptor for Swift.Equatable

:-1: Undefined symbol: method descriptor for static Swift.Equatable.== infix(A, A) -> Swift.Bool

:-1: Undefined symbol: protocol descriptor for Swift.ExpressibleByArrayLiteral

:-1: Undefined symbol: type metadata for Swift.Int32

:-1: Undefined symbol: associated type descriptor for ArrayLiteralElement

:-1: Undefined symbol: base conformance descriptor for Swift.OptionSet: Swift.SetAlgebra

:-1: Undefined symbol: method descriptor for Swift.OptionSet.init(rawValue: A.RawValue) -> A

:-1: Undefined symbol: method descriptor for Swift.RawRepresentable.rawValue.getter : A.RawValue

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.init() -> A

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.union(__owned A) -> A

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.intersection(A) -> A

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.insert(__owned A.Element) -> (inserted: Swift.Bool, memberAfterInsert: A.Element)

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.update(with: __owned A.Element) -> A.Element?

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.formIntersection(A) -> ()

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.subtracting(A) -> A

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.isDisjoint(with: A) -> Swift.Bool

:-1: Undefined symbol: _swift_allocBox

:-1: Undefined symbol: _swift_getObjectType

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.isSuperset(of: A) -> Swift.Bool

:-1: Undefined symbol: protocol witness table for Swift.Float : Swift.CustomStringConvertible in Swift

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.isEmpty.getter : Swift.Bool

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.init(__owned A1) -> A

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.subtract(A) -> ()

:-1: Undefined symbol: type metadata accessor for Swift.Dictionary

:-1: Undefined symbol: (extension in CoreMedia):__C.CMTime.seconds.getter : Swift.Double

:-1: Undefined symbol: base conformance descriptor for Swift.SetAlgebra: Swift.Equatable

:-1: Undefined symbol: _swift_unknownObjectRetain

:-1: Undefined symbol: type metadata for Swift.AnyObject

:-1: Undefined symbol: _swift_dynamicCast

:-1: Undefined symbol: Swift._forceBridgeFromObjectiveC_bridgeable(A._ObjectiveCType, A.Type) -> A

:-1: Undefined symbol: (extension in Swift):Swift.Collection< where A.Iterator == Swift.IndexingIterator>.makeIterator() -> Swift.IndexingIterator

:-1: Undefined symbol: (extension in Foundation):Swift.StringProtocol.replacingOccurrences(of: A1, with: B1, options: __C.NSStringCompareOptions, range: Swift.Range?) -> Swift.String

:-1: Undefined symbol: protocol conformance descriptor for Swift.UInt : Swift.FixedWidthInteger in Swift

:-1: Undefined symbol: Foundation.Data.write(to: Foundation.URL, options: __C.NSDataWritingOptions) throws -> ()

:-1: Undefined symbol: method descriptor for Swift.SetAlgebra.formUnion(__owned A) -> ()

:-1: Undefined symbol: (extension in Swift):Swift.SetAlgebra.subtract(A) -> ()

:-1: Undefined symbol: value witness table for Builtin.UnknownObject

:-1: Undefined symbol: (extension in Swift):Swift.SetAlgebra.subtracting(A) -> A

:-1: Undefined symbol: (extension in Swift):Swift.OptionSet< where A.RawValue: Swift.FixedWidthInteger>.formSymmetricDifference(A) -> ()

:-1: Undefined symbol: (extension in Swift):Swift.OptionSet< where A == A.Element>.update(with: A) -> A?

:-1: Undefined symbol: Foundation.Data._bridgeToObjectiveC() -> __C.NSData

:-1: Undefined symbol: (extension in Swift):Swift.OptionSet.union(A) -> A

:-1: Undefined symbol: Foundation.URL.absoluteString.getter : Swift.String

:-1: Undefined symbol: associated type descriptor for Element

:-1: Undefined symbol: type metadata accessor for Swift.Array

:-1: Undefined symbol: _swift_errorRelease

:-1: Undefined symbol: _swift_release

:-1: Undefined symbol: _swift_getForeignTypeMetadata

:-1: Undefined symbol: Swift.Double.init(Swift.Double) -> Swift.Double

:-1: Undefined symbol: type metadata for Swift.Int

:-1: Undefined symbol: type metadata for Any

:-1: Undefined symbol: type metadata accessor for Swift.Optional

:-1: Undefined symbol: _swift_retain

:-1: Undefined symbol: Swift._allocateUninitializedArray(Builtin.Word) -> ([A], Builtin.RawPointer)

:-1: Undefined symbol: protocol witness table for Swift.String : Swift.Hashable in Swift

:-1: Undefined symbol: static Swift.Array._allocateBufferUninitialized(minimumCapacity: Swift.Int) -> Swift._ArrayBuffer

:-1: Undefined symbol: (extension in Swift):Swift.SignedInteger< where A: Swift.FixedWidthInteger>.init(A1) -> A

:-1: Undefined symbol: (extension in Swift):Swift.OptionSet< where A.RawValue: Swift.FixedWidthInteger>.formUnion(A) -> ()

:-1: Undefined symbol: (extension in Swift):Swift.OptionSet< where A.RawValue: Swift.FixedWidthInteger>.init() -> A

:-1: Undefined symbol: type metadata for CoreGraphics.CGFloat

:-1: Undefined symbol: Swift.== infix(A, A) -> Swift.Bool

:-1: Undefined symbol: (extension in Swift):Swift.SetAlgebra< where A.ArrayLiteralElement == A.Element>.init(arrayLiteral: A.ArrayLiteralElement...) -> A

:-1: Undefined symbol: (extension in Foundation):Swift.String.Encoding.rawValue.getter : Swift.UInt

:-1: Undefined symbol: Foundation.URL.init(fileURLWithPath: __shared Swift.String) -> Foundation.URL

:-1: Undefined symbol: protocol conformance descriptor for [A] : Swift.RangeReplaceableCollection in Swift

:-1: Undefined symbol: (extension in Foundation):Swift.StringProtocol.components(separatedBy: A1) -> [Swift.String]

:-1: Undefined symbol: Swift.abs(A) -> A

:-1: Undefined symbol: (extension in Swift):Swift.OptionSet< where A == A.Element>.remove(A) -> A?

:-1: Undefined symbol: generic specialization  of Swift.Array.count.getter : Swift.Int

:-1: Undefined symbol: (extension in Swift):Swift.RangeReplaceableCollection< where A: Swift.BidirectionalCollection>.removeLast() -> A.Element

:-1: Undefined symbol: type metadata for Swift.Int64

:-1: Undefined symbol: (extension in Swift):Swift.SetAlgebra.init(__owned A1) -> A

:-1: Undefined symbol: _swift_getExistentialTypeMetadata

:-1: Undefined symbol: type metadata accessor for Swift.IndexingIterator

:-1: (86 additional undefined symbols are shown in the transcript

解决办法也有点特别,但确实有效:

  • 1、在Xcode打开 ios/App名.xcodeproj;(这个目录跟 RunnerPods 在同一级目录下,不能同时打开,我是关闭工程,再用Xcode 打开新项目)
  • 2、右键项目名(我的是 Runner),新建一个swift 文件,文件名随意,也不需要写内容, Xcode 提示 Create Bridging Header 的话点击(我的没有提示,应该是之前已经新建过了);
  • 3、不要删除新建的.swift文件,重新 build 项目,就成功了。

方法来源:https://github.com/mxcl/PromiseKit/issues/1059#issuecomment-493925940

你可能感兴趣的:(Flutter导入flutter_video_compress遇到的问题)