React Native ios - 架构 x86_64 的未定义符号

jam*_*phy 20 xcode objective-c clang react-native

我已经构建了一个在 android 中运行良好的 React Native 应用程序......但是当我尝试在 ios 中构建时出现以下错误:Undefined symbols for architecture x86_64 它似乎以某种方式链接到 Flipper,详细错误如下:

     link with file built for iOS Simulator-arm64
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FlipperKitNetworkPlugin", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_FlipperKitReactPlugin", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_SKDescriptorMapper", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_FlipperClient", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RNCPushNotificationIOS", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_FlipperKitLayoutPlugin", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RCTRootView", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RCTBridge", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_SKIOSNetworkAdapter", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_RCTBundleURLProvider", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_FBSDKApplicationDelegate", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_FIRApp", referenced from:
      objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_FKUserDefaultsPlugin", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

Z H*_* Hu 61

我在 m1 上遇到了同样的问题,这样做帮助我解决了问题:

修改Build Settings -> Excluded Architectures选项,添加Any iOS Simulator SDK选项,并将值设置为arm64。如图:

在此输入图像描述

并在Podfile中添加以下代码:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = "arm64"
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

  • 创建静态库时,会针对实际设备(arm64)和模拟器(x86_64)分别打包一个版本。在Intel Mac上,使用x86_64指令的模拟器没有问题,但在M1 Mac上就会出现问题。排除arm64架构后,模拟器仍会运行在arm64模式下,但模拟器中的app运行在x86模式下。https://juejin.cn/post/7037037120158269448 (2认同)