iOS无CocoaPods集成Firebase ML Kit时GoogleMobileVision链接错误
问题描述
我正尝试在不使用CocoaPods的Xcode项目中集成Firebase 5.0.1的MLVisionTextModel,已按照Readme.md文件添加所有依赖框架,但出现以下链接错误:
Showing All Messages
"OBJC_CLASS$_LAContext", referenced from:
objc-class-ref in GoogleMobileVision(MDMPasscodeCache_f189776e75765630b82721fafea64052.o)
"_vImageConverter_CreateWithCGImageFormat", referenced from:
+[GMVUtility(Internal) sampleBuffer32BGRATo32RGBA:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
"_vImageConvert_AnyToAny", referenced from:
+[GMVUtility(Internal) sampleBuffer32BGRATo32RGBA:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
"_vImageConverter_Release", referenced from:
+[GMVUtility(Internal) sampleBuffer32BGRATo32RGBA:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
"_vImageBuffer_InitWithCGImage", referenced from:
+[GMVUtility(Internal) rgbaPixelDataFromCGImage:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
"_vImageRotate_ARGB8888", referenced from:
+[GMVUtility(Internal) rotatePixelData:width:height:bytesPerRow:withAngle:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
"_vImageHorizontalReflect_ARGB8888", referenced from:
+[GMVUtility(Internal) flipRGBA8888Horizontally:width:height:bytesPerRow:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
"_vImagePermuteChannels_ARGB8888", referenced from:
+[GMVUtility(Internal) permutate:width:height:bytesPerRow:order:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
"_vImageFlatten_RGBA8888ToRGB888", referenced from:
+[GMVUtility(Internal) flattenRGBA8888ToRGB888:width:height:bytesPerRow:] in GoogleMobileVision(GMVUtility+Internal_1a3089c1f18dbb4046735909972b8cb2.o)
ld: symbol(s) not found for architecture x86_64
问题分析
这些错误都是因为项目缺少了两个GoogleMobileVision依赖的系统框架:
_OBJC_CLASS_$_LAContext来自 LocalAuthentication.framework:这个框架用于处理设备密码验证相关逻辑,GoogleMobileVision的密码缓存模块用到了它- 所有
vImage*开头的符号来自 Accelerate.framework:这是苹果提供的高性能计算框架,GoogleMobileVision用它来处理图像的转换、旋转、通道排列等操作
解决步骤
- 打开你的Xcode项目,选中需要集成的目标(target)
- 切换到Build Phases标签页
- 找到并展开Link Binary With Libraries选项
- 点击列表下方的
+按钮,在搜索框中分别搜索并添加:LocalAuthentication.frameworkAccelerate.framework
- 完成添加后,重新编译你的项目,这些链接错误应该就能被解决了
手动集成第三方库时,经常会遇到这种隐式依赖的系统框架缺失问题,毕竟CocoaPods会自动帮我们处理这些依赖关系,手动操作就得自己排查这类符号缺失的问题啦。
内容的提问来源于stack exchange,提问作者avdhut

