You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native 0.64.4在M1芯片MacBook上iOS编译失败求助

React Native 0.64.4 在M1 Mac上运行iOS应用报错:arm64架构Swift符号缺失

问题描述

我有一个React Native 0.64.4版本的项目,在Intel芯片Mac上能正常运行(已正确执行pod install),但在M1芯片MacBook上执行npx react-native run-ios时出现链接错误。

环境信息

react-native info  
System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1
    Memory: 113.38 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.6.0 - /opt/homebrew/bin/node
    Yarn: Not Found
    npm: 9.4.0 - /opt/homebrew/bin/npm
    Watchman: 2023.02.06.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/accelerlabsolutions/.rvm/gems/ruby-2.7.6/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9477386
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.17 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: ^0.64.1 => 0.64.4 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

执行命令

npx react-native run-ios

错误信息

"_swift_unknownObjectWeakInit", referenced from:
      _$s9InputMask23MaskedTextFieldDelegateC13primaryFormat12autocomplete0I7OnFocus8autoskip11rightToLeft13affineFormats27affinityCalculationStrategy15customNotations02oncD15ChangedCallback16allowSuggestionsACSS_S4bSaySSGAA08AffinitysT0OSayAA8NotationVGySo06UITextA0_p_SSSbtcSgSbtcfc in libInputMask.a(MaskedTextFieldDelegate.o)
      _$s9InputMask23MaskedTextFieldDelegateCACycfc in libInputMask.a(MaskedTextFieldDelegate.o)
      _$s9InputMask22MaskedTextViewDelegateC13primaryFormat12autocomplete0I7OnFocus8autoskip11rightToLeft13affineFormats27affinityCalculationStrategy15customNotations02oncD15ChangedCallback16allowSuggestionsACSS_S4bSaySSGAA08AffinitysT0OSayAA8NotationVGySo06UITextA0_p_SSSbtcSgSbtcfc in libInputMask.a(MaskedTextViewDelegate.o)
      _$s9InputMask22MaskedTextViewDelegateCACycfc in libInputMask.a(MaskedTextViewDelegate.o)
      _$s9InputMask010MaskedTextA8ListenerC13primaryFormat12autocomplete0H7OnFocus8autoskip11rightToLeft13affineFormats27affinityCalculationStrategy15customNotations02oncD15ChangedCallback16allowSuggestionsACSS_S4bSaySSGAA08AffinityrS0OSayAA8NotationVGySo06UITextA0_p_SSSbtcSgSbtcfc in libInputMask.a(MaskedTextInputListener.o)
      _$s9InputMask010MaskedTextA8ListenerCACycfc in libInputMask.a(MaskedTextInputListener.o)
  "_swift_unknownObjectWeakLoadStrong", referenced from:
      _$s9InputMask23MaskedTextFieldDelegateC8listenerAA0cdeF8Listener_pSgvg in libInputMask.a(MaskedTextFieldDelegate.o)
      _$s9InputMask23MaskedTextFieldDelegateC8listenerAA0cdeF8Listener_pSgvM in libInputMask.a(MaskedTextFieldDelegate.o)
      _$s9InputMask22MaskedTextViewDelegateC8listenerAA0cdeF8Listener_pSgvg in libInputMask.a(MaskedTextViewDelegate.o)
      _$s9InputMask22MaskedTextViewDelegateC8listenerAA0cdeF8Listener_pSgvM in libInputMask.a(MaskedTextViewDelegate.o)
      _$s9InputMask010MaskedTextA8ListenerC8listenerAA02Oncd7ChangedE0_pSgvg in libInputMask.a(MaskedTextInputListener.o)
      _$s9InputMask010MaskedTextA8ListenerC8listenerAA02Oncd7ChangedE0_pSgvM in libInputMask.a(MaskedTextInputListener.o)
  "_swift_updateClassMetadata2", referenced from:
      _$s9InputMask18OptionalValueStateCMr in libInputMask.a(OptionalValueState.o)
  "_swift_willThrow", referenced from:
      _$s9InputMask8CompilerC22determineInheritedType33_B3F36BB0FA1A2C10D03E581AB8FCA34DLL16forLastCharacterAA10ValueStateC0uF0OSJSg_tKF in libInputMask.a(Compiler.o)
      _$s9InputMask8CompilerC26compileWithCustomNotations33_B3F36BB0FA1A2C10D03E581AB8FCA34DLL_6stringAA5StateCSJ_SStKF in libInputMask.a(Compiler.o)
      _$s9InputMask8CompilerC24determineCustomStateType33_B3F36BB0FA1A2C10D03E581AB8FCA34DLL12forCharacterAA05ValueF0C0fG0OSJ_tKF in libInputMask.a(Compiler.o)
      _$s9InputMask15FormatSanitizerC15checkOpenBraces33_9630C2BFB0C1EEC80D8C490909BFFB6BLLyySSKF in libInputMask.a(FormatSanitizer.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

诉求

成功运行该iOS应用。


解决方案

  • 添加Swift空文件到项目:
    由于项目依赖Swift编写的InputMask库,但主项目无Swift代码,导致Xcode未正确链接Swift标准库。打开Xcode项目,右键目录选择New File,创建空Swift文件(如Dummy.swift),Xcode提示创建Bridging Header时选择创建即可。

  • 修改Podfile适配M1架构:
    在ios/Podfile开头添加以下配置:

    platform :ios, '11.0'
    archs = ['arm64', 'x86_64']
    installer.pods_project.build_configurations.each do |config|
      config.build_settings['ARCHS'] = archs.join(' ')
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
    end
    

    然后重新执行:

    cd ios
    pod deintegrate
    pod install
    
  • 使用Rosetta终端执行命令:
    右键终端图标选择Get Info,勾选使用Rosetta打开,再重新执行npx react-native run-ios,部分旧库需通过Rosetta兼容Intel架构构建。

  • 更新InputMask库版本:
    检查项目中react-native-input-mask或原生InputMask版本,更新至支持arm64的版本,修改package.json后重新安装依赖和pods。

  • 调整Xcode架构设置:
    打开Xcode项目,选择目标应用进入Build Settings:

    • 将Architectures设为Standard Architectures (arm64, x86_64)
    • 将Build Active Architecture Only设为NO
    • 在Excluded Architectures的Debug和Release中添加arm64(模拟器运行时)或移除相关限制

内容的提问来源于stack exchange,提问作者Nishanth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 13:35:19