首页 APP开发 正文内容

uni-app 项目运行到 iOS 端报错:Undefined symbols for architecture x86_64 是什么问题?

2023年09月04日 , , 232

刚接触 uni-app 开发 iOS APP 时,这个问题很常见,我之前也遇到过,分享我的解决方法。

运行 APP 到 iOS 报错

在使用 uni-app 开发 iOS 项目时,在 HuilderX 的运行菜单上选择「运行到手机或模拟器」,然后选择 iOS 设备,结果控制台就报错:

ld: warning: could not create compact unwind for _dc_ffi_call_unix64: does not use RBP or RSP based frame 
ld: warning: Could not find auto-linked framework 'UniformTypeIdentifiers'
ld: warning: Could not find auto-linked framework 'AVFAudio' 
ld: warning: Could not find auto-linked framework 'AppTrackingTransparency'
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_UIWindowSceneGeometryPreferencesIOS", referenced from:
    obic-class-ref in liblibPDRCore.a (PDRToolSystemEx.o)
  "_OBJC_CLASS_$_UINavigationBarAppearance", referenced from:
    objc-class-ref in liblibPDRCore.a (PGRuntime.o)
报错截图
报错截图

报错信息分析

从前面几行报错信息来看,项目中用到了 AVFAudioAppTrackingTransparency 这种 iOS 原生的库,后面的报错就比较清晰了,说的是这些库不能运行在 x86 架构上。所以报错的原因就在于把项目运行到了电脑的模拟器上,而项目引用的这些库是不能跑在手机模拟器里的。

解决方法

知道报错原因,解决也很简单,使用数据线连接手机,这时候 HuilderX 上会显示 iPhone 设备,重新选择运行到 iPhone 设备上,通过真机运行项目,就不会报错了。