Swift linker error: Undefined symbol for surely available API presentationDimensions

Swift linker error: Undefined symbol for surely available API presentationDimensions

我正在开发一个使用 presentationDimensions(...) API:

的相机应用程序
if #available(iOS 13.0, *) {
  let leftVideo = self.formatDescription.presentationDimensions()
  let rightVideo = other.formatDescription.presentationDimensions()
  // ...
}

现在,当我尝试构建项目时,出现以下错误:

Undefined symbol: (extension in CoreMedia):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize

这是最后一个 Xcode 日志(错误):

Ld /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/VisionCameraExample.app/VisionCameraExample normal (in target 'VisionCameraExample' from project 'VisionCameraExample')
    cd /Users/mrousavy/Projects/react-native-vision-camera/example/ios
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios12.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/CocoaAsyncSocket -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/DoubleConversion -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/FBReactNativeSpec -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-DoubleConversion -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-Folly -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-Glog -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-PeerTalk -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-RSocket -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/FlipperKit -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Folly -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/RCTTypeSafety -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-Core -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-CoreModules -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTAnimation -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTBlob -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTImage -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTLinking -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTNetwork -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTSettings -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTText -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTVibration -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-cxxreact -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-jsi -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-jsiexecutor -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-jsinspector -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/ReactCommon -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Yoga -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/YogaKit -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/glog -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/libevent -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/react-native-vision-camera -F/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos -F/Users/mrousavy/Projects/react-native-vision-camera/example/ios/Pods/OpenSSL-Universal/Frameworks -F/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/OpenSSL -filelist /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample.LinkFileList -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-arc -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample.swiftmodule -ObjC -lCocoaAsyncSocket -lDoubleConversion -lFBReactNativeSpec -lFlipper -lFlipper-DoubleConversion -lFlipper-Folly -lFlipper-Glog -lFlipper-PeerTalk -lFlipper-RSocket -lFlipperKit -lFolly -lRCTTypeSafety -lReact-Core -lReact-CoreModules -lReact-RCTAnimation -lReact-RCTBlob -lReact-RCTImage -lReact-RCTLinking -lReact-RCTNetwork -lReact-RCTSettings -lReact-RCTText -lReact-RCTVibration -lReact-cxxreact -lReact-jsi -lReact-jsiexecutor -lReact-jsinspector -lReactCommon -lYoga -lYogaKit -lglog -llibevent -lreact-native-vision-camera -lstdc++ -framework AudioToolbox -framework CFNetwork -framework JavaScriptCore -framework MobileCoreServices -framework OpenSSL -framework Security -framework UIKit -ObjC -lc++ -lPods-VisionCameraExample -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample_dependency_info.dat -o /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/VisionCameraExample.app/VisionCameraExample

Undefined symbols for architecture arm64:
  "(extension in CoreMedia):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize", referenced from:
      (extension in react_native_vision_camera):__C.AVCaptureDeviceFormat.isBetterThan(__C.AVCaptureDeviceFormat) -> Swift.Bool in libreact-native-vision-camera.a(AVCaptureDevice.Format+isBetterThan.o)
      (extension in react_native_vision_camera):__C.AVCaptureDeviceFormat.matchesFilter(__C.NSDictionary) -> Swift.Bool in libreact-native-vision-camera.a(AVCaptureDevice.Format+matchesFilter.o)
      (extension in react_native_vision_camera):__C.AVCaptureDeviceFormat.toDictionary() -> [Swift.String : Any] in libreact-native-vision-camera.a(AVCaptureDevice.Format+toDictionary.o)
     (maybe you meant: default argument 1 of (extension in CoreMedia):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize, default argument 0 of (extension in CoreMedia):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize )
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我的.pbxproj(删除了不相关的部分,如发布配置等):

// ...

/* Begin XCBuildConfiguration section */
        13B07F941A680F5B00A75B9A /* Debug */ = {
            isa = XCBuildConfiguration;
            baseConfigurationReference = 47F7ED3B7971BE374F7B8635 /* Pods-VisionCameraExample.debug.xcconfig */;
            buildSettings = {
                ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
                CLANG_ENABLE_MODULES = YES;
                CURRENT_PROJECT_VERSION = 1;
                DEVELOPMENT_TEAM = CJW62Q77E7;
                ENABLE_BITCODE = NO;
                INFOPLIST_FILE = VisionCameraExample/Info.plist;
                LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
                OTHER_LDFLAGS = (
                    "$(inherited)",
                    "-ObjC",
                    "-lc++",
                );
                PRODUCT_BUNDLE_IDENTIFIER = com.example.reactnativevisioncamera;
                PRODUCT_NAME = VisionCameraExample;
                SWIFT_OBJC_BRIDGING_HEADER = "VisionCameraExample-Bridging-Header.h";
                SWIFT_OPTIMIZATION_LEVEL = "-Onone";
                SWIFT_VERSION = 5.0;
                VERSIONING_SYSTEM = "apple-generic";
            };
            name = Debug;
        };

// ...

        83CBBA201A601CBA00E9B192 /* Debug */ = {
            isa = XCBuildConfiguration;
            buildSettings = {
                ALWAYS_SEARCH_USER_PATHS = NO;
                CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
                CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
                CLANG_CXX_LIBRARY = "libc++";
                CLANG_ENABLE_MODULES = YES;
                CLANG_ENABLE_OBJC_ARC = YES;
                CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
                CLANG_WARN_BOOL_CONVERSION = YES;
                CLANG_WARN_COMMA = YES;
                CLANG_WARN_CONSTANT_CONVERSION = YES;
                CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
                CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
                CLANG_WARN_EMPTY_BODY = YES;
                CLANG_WARN_ENUM_CONVERSION = YES;
                CLANG_WARN_INFINITE_RECURSION = YES;
                CLANG_WARN_INT_CONVERSION = YES;
                CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
                CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
                CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
                CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
                CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
                CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
                CLANG_WARN_STRICT_PROTOTYPES = YES;
                CLANG_WARN_SUSPICIOUS_MOVE = YES;
                CLANG_WARN_UNREACHABLE_CODE = YES;
                CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
                "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
                COPY_PHASE_STRIP = NO;
                ENABLE_STRICT_OBJC_MSGSEND = YES;
                ENABLE_TESTABILITY = YES;
                GCC_C_LANGUAGE_STANDARD = gnu99;
                GCC_DYNAMIC_NO_PIC = NO;
                GCC_NO_COMMON_BLOCKS = YES;
                GCC_OPTIMIZATION_LEVEL = 0;
                GCC_PREPROCESSOR_DEFINITIONS = (
                    "DEBUG=1",
                    "$(inherited)",
                );
                GCC_SYMBOLS_PRIVATE_EXTERN = NO;
                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
                GCC_WARN_UNDECLARED_SELECTOR = YES;
                GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
                GCC_WARN_UNUSED_FUNCTION = YES;
                GCC_WARN_UNUSED_VARIABLE = YES;
                IPHONEOS_DEPLOYMENT_TARGET = 12.0;
                LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)";
                LIBRARY_SEARCH_PATHS = (
                    "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
                    "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
                    "\"$(inherited)\"",
                );
                MTL_ENABLE_DEBUG_INFO = YES;
                ONLY_ACTIVE_ARCH = YES;
                SDKROOT = iphoneos;
            };
            name = Debug;
        };

// ...

请注意,当我删除对 presentationDimensions 的那些调用时,一切正常。

有人可以帮我吗? API 从 iOS 13.0 开始可用,即使我的 iOS 部署目标是 11.0,我仍然应该能够构建它,不是吗?

终于找到答案了。我将 SWIFT_VERSION 固定到 5.0,但是 iOS 13 附带了 Swift 5.2,所以将 Swift 固定到 5.2(并删除指向 5.0 的 LIBRARY_SEARCH_PATH)解决了它.

也就是说,这个:

                LIBRARY_SEARCH_PATHS = (
                    "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
                    "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
                    "\"$(inherited)\"",
                );
                SWIFT_VERSION = 5.0;

应该是这样的:

                LIBRARY_SEARCH_PATHS = (
                    "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
                    "\"$(inherited)\"",
                );
                SWIFT_VERSION = 5.2;

耶稣基督。

在我的例子中,我只需要删除我的 DerivedData 文件夹内容 (~/Library/Developer/Xcode/DerivedData/)

在我的例子中,一个函数在我的框架中声明为私有,测试目标看不到异步方法,将其声明为内部修复了我的问题。