【问题标题】:xCode Cocoapods build fails "Undefined symbols for architecture x86_64"xCode Cocoapods 构建失败“架构 x86_64 的未定义符号”
【发布时间】:2021-06-27 08:30:25
【问题描述】:

我想为模拟器和真实设备构建我的 Xcode 项目(react native & swift)。

模拟器运行良好。今天我尝试为我的设备构建它,我在 Xcode 栏中选择了我的设备并添加了要发布的方案(我必须这样做,因为我使用的是 react native,否则捆绑包没有打包)

然后在构建过程中发生错误(在这种情况下是依赖 RNPurchases,但这完全是随机的。有时是 Expo-Keep-Awake 或 Facebook)

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_RCPurchases", referenced from:
  objc-class-ref in RNPurchases.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

即使在我的方案中切换回构建配置Debug 也不再有效。

我已经尝试了几件事:

  • 清除 Xcode 构建
  • 删除 pod 文件夹
  • 移除 pod 缓存
  • 移除 Xcode/DerivedData
  • 重启

没有任何作用。

这个问题对我来说很新,在过去 2 个月内已经发生过两次。不知何故,我让模拟器的构建再次运行,但从未用于设备。半年前我没遇到过这样的问题……

我的设置

  • Xcode 12.4
  • MacBook Pro(大苏尔 11.2.3)
  • App-Target 的构建设置:仅构建活动架构:Debug YES,Release NO)
  • Pod-Target 的构建设置:仅构建活动架构:Debug YES,Release NO)
  • 播客文件:

    require_relative '../node_modules/react-native/scripts/react_native_pods'
    require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
    require_relative '../node_modules/react-native-unimodules/cocoapods.rb' # expo uni modules

    use_frameworks!

    install! 'cocoapods', :deterministic_uuids => false, :warn_for_unused_master_specs_repo => false


    target 'TrainUrTeam' do
      platform :ios, '12.0'

      # ... pods xyz

      use_unimodules!

      config = use_native_modules!
      use_react_native!(:path => config["reactNativePath"])

    end


    post_install do |installer| # src: https://stackoverflow.com/a/64139830/6003494
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings["ONLY_ACTIVE_ARCH"] = "YES"
        end
      end
    end

【问题讨论】:

    标签: ios swift xcode react-native cocoapods


    【解决方案1】:

    经过 2 周的谷歌搜索,我终于可以根据 Post 找到一个可行的解决方案,并将其添加到 Podfile

    use_frameworks! :linkage => :static
    

    【讨论】:

      【解决方案2】:

      如果use_frameworks! :linkage => :static 不适合您,您可以尝试使用:

      pre_install do |installer|
       installer.pod_targets.each do |pod|
         if pod.name.eql?('RNPurchases')
           def pod.build_type;
           Pod::BuildType.static_library # pods version >= 1.9
           # Pod::Target::BuildType.static_library #  pods version < 1.9
          end
         end
       end
      

      结束

      【讨论】:

        【解决方案3】:

        转到 xcode 项目 -> 构建设置 -> 架构 -> 排除 架构 -> (arm64)set

        尝试构建并运行

        【讨论】:

        • 是的,但它不起作用...错误消息显示“架构 x86_64 的未定义符号”为什么 arm64 应该工作?
        猜你喜欢
        • 2015-09-05
        • 1970-01-01
        • 2018-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-13
        • 2021-03-12
        • 2016-11-07
        相关资源
        最近更新 更多