Cocoapods project fails to build on an Apple Silicon / M1 Mac

Viewed 1162

Before you think that this is a duplicate:

There are several posts on this failing, but most of them are old posts not related to M1 Macs and some have contradictory solutions. This post is only for M1 Macs using Cocoapods with the following setup:

The setup

  • Cocoapods 1.10.1
  • Cocoapods configuration has generate_multiple_pod_projects and incremental_installation enabled
  • Terminal is set up to use Rosetta 2 to solve issues with Cocoapods
  • Several libraries used, such as Firebase, RxSwift etc and NearbyMessages

The problem

Compiling the project (that works on an intel computer) yields the following error for the NearbyMessages library from Google:

In /Users/user/Pods/NearbyMessages/Libraries/libGNSMessages.a(GNSAudioModem.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/user/Pods/NearbyMessages/Libraries/libGNSMessages.a' for architecture arm64

The most common suggestions are to add arm64 to "Excluded Architectures" and to set "Build Active Architectures Only" to YES (which is default). Other posts say that the latter should be NO. Setting this to No will instead give me the error No such module 'RxSwift'.

Adding arm64 to "Excluded Architectures" would also mean that I would need the following post install to all generated projects (since I am using generate_multiple_pod_projects) in the Pod file:

post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
      end
    end
  end
end

What I want to understand is if this is the correct approach. Not just try different settings and hope for the best, but to understand why this would help. Why would I exclude arm64 when the M1 chip is arm64? Have I been using the wrong solutions? Any help would be appreciated.

2 Answers

The NearbyMessages binary pod distribution has not been updated with a slice to support the M1 Mac. Therefore it is not possible to link it into an app and build it for the simulator.

config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64e"

Initially with e in the end.

Related