Search code examples
iosswiftxcodereact-nativecocoapods

xCode Cocoapods build fails "Undefined symbols for architecture x86_64"


I want to build my Xcode project (react native & swift) for the simulator and on a real device.

The simulator worked great. Today I tried to build it for my device, I selected my device in the Xcode bar and added the scheme to release (I had to do this because I'm using react native and otherwise the bundle is not packed)

Then an error during the build occurs (in this case for the dependency RNPurchases, but this is completely random. sometimes it's Expo-Keep-Awake or 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)

Even switching the back to Build Configuration Debug in my scheme has no effect anymore.

I already tried several things:

  • clear Xcode build
  • delete pod folder
  • remove pod cache
  • remove Xcode/DerivedData
  • reboot

nothing works.

This problem is pretty new to me, it already occurred twice within the last 2 months. Somehow I got the build for the simulator running again, but never for a device. I didn't have the problems like this half a year ago ...

My Setup

  • Xcode 12.4
  • MacBook Pro (Big Sur 11.2.3)
  • Build Settings for App-Target: Build Active Architectures Only: Debug YES, Release NO)
  • Build Settings for Pod-Target: Build Active Architectures Only: Debug YES, Release NO)
  • Podfile:

    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

Solution

  • After 2 weeks of googling I could finally find a working solution according to this Post adding this to the Podfile:

    use_frameworks! :linkage => :static