7

After upgrading xcode12,build issus:

ld :building for iOS Simulator, but linking in object file built for iOS, file 'xxx.framework/xxx' for architecture arm64

It can run on iPhone

burningsun
  • 248
  • 1
  • 2
  • 11
  • Using Xcode 11.* version to open the project and Set empty value for Vaild Architectures Then open it on Xcode 12 have a try good luck. – JNYJ Sep 17 '20 at 06:57
  • This doesn't work for me @JNYJ ,and Xcode 11 'Vaild Architectures' == 'VALID_ARCHS' in Xcode 12 – burningsun Sep 17 '20 at 08:00

1 Answers1

22

The Build Settings editor no longer includes the Valid Architectures build setting "VALID ARCHS", and its use is discouraged. Instead, there is a new Excluded Architectures build setting (EXCLUDED ARCHS)

Xcode 12 is actually the stepping stone for Apple Silicon which unfortunately is not yet available. But with that platform, we are gonna get arm64 based macOS where simulators will also run on arm64 architecture unlike the present Intel-based x86_64 architecture.

Xcode usually depends on the "Run Destination" to build its libraries/apps. So when a simulator is chosen as the "Run Destination", it builds the app for available simulator architectures and when a device is chosen as the "Run Destination" it builds for the architecture that the device supports (arm*).

xcodebuild, in the Xcode 12+ build system, considers arm64 as a valid architecture for the simulator. So when a simulator is chosen as the run destination, it can potentially try to compile/link your libs/apps against arm64 based simulators as well (not available yet). So it sends clang(++) some -target flag like arm64-apple-ios13.0-simulator in --- format and clang tries to build/link against arm64 based simulator that eventually fails on Intel-based mac.

But xcodebuild tries this only for Release builds. Why? Because, "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" build settings is usually set to "No" for the "Release" configuration only. And that means xcodebuild will try to build all architectural variants of your libs/apps for the selected run destination for release builds. And for the Simulator run destination, it will includes both x86_64 and arm64 now on, since arm64 in Xcode 12+ is also a supported architecture for simulators to support Apple Silicon.

Simply putting, Xcode will fail to build your app anytime it tries the command line, xcodebuild, (which defaults to release build, see the general tab of your project setting) or otherwise in release mode. So a simple workaround to this issue is to set "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" to Yes in your libraries/apps, even for release mode.

Select Traget then go to build setting

Steps to resolve the issue :

Solution 1:

  1. Select Project Target
  2. Go to build setting
  3. Select All
  4. search for "Build Active Architecture Only"
  5. Build Active Architecture Only to "Yes" even for release mode.
  6. Build Again

Solution 2:

  1. Select Project Target
  2. Go to build setting
  3. Select All
  4. search for "Excluded Architecture"
  5. Add "arm64" to both Release and Debug mode for the "Any iOS Simulator SDK" option.
  6. Build Again

enter image description here

Avneesh Agrawal
  • 916
  • 6
  • 11
  • 1
    For Apple silicon Mac users, would Solution #2 still make sense? I tried #1 and it seem to make no difference, which is weird because Apple silicon Mac should support arm64 simulator natively. – user482594 Jan 31 '21 at 14:28
  • After any of these 2 solutions, despite it builds, it says it can't install on simulator because it can't find a Info.plist from this lib RealmSwift.framework. I wonder if this lib is not being included in the build process because (not sure) it only supports arm64 processors. – ofundefined Feb 23 '21 at 17:52