Xcode 12 beta 4 - error compiling for Simulator

An existing framework library workspace compiles without error when targeting iOS device architecture, but when targeting Simulator I receive the following error:

Code Block
Code Block
ld: in /Users/macbook/Documents/Projects/iOS/HungerStation/Code/customer-app-ios/Pods/mopub-ios-sdk/MoPubSDK/Viewability/MOAT/MPUBMoatMobileAppKit.framework/MPUBMoatMobileAppKit(MPUBMoatAnalytics.o), building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

As per this https://developer.apple.com/forums/thread/655316

Changing build setting "Build Active Architecture Only" from No to Yes doesn't solve this problem

Has anyone else seen this?
Post marked as unsolved Up vote post of kiji123 Down vote post of kiji123
4.6k views

35 Replies

Add line "arm64" (without quotes) to path: Xcode -> Project -> Build settings -> Architectures -> Excluded architectures
Also do the same for Pods. In both cases for both debug and release fields.
I hope this will help.
Best regards.
Lost 2 days on this - bah! Want to give REAL Kudos to those who actually helped solve this problem:

stschwar @ github in this post: https://github.com/CocoaPods/CocoaPods/issues/10059
pointed to this SO post with a simple solution: https://stackoverflow.com/questions/63391793/xcode-12-build-target-in-wrong-order/63405201#63405201

XCode has a deserved 3 stars for many reasons, this is one of them! Counterproductivity kills.
CVD442 Thanks for your solution:


Errors mentioned in here while deploying to simulator using xcode 12 are also one of the things which have affected me. Just right clicking on each of my projects and showing in finder, opening the .xcodeproj in Atom, then going through the .pbxproj and removing all of the VALIDARCHS settings. This was is what got it working for me.
Tried a few of the other suggestions (excluding arm64, Build Active Architecture Only) which seemed to get my build further but ultimately leave me at another error. Having VALIDARCH settings lying around is probably best thing to check for first.


Errors mentioned in here while deploying to simulator using xcode 12 are also one of the things which have affected me. Just right clicking on each of my projects and showing in finder, opening the .xcodeproj in Atom, then going through the .pbxproj and removing all of the VALIDARCHS settings. This was is what got it working for me.

Tried a few of the other suggestions (excluding arm64, Build Active Architecture Only) which seemed to get my build further but ultimately leave me at another error. Having VALID
ARCH settings lying around is probably best thing to check for first.
Hello,

To all the people with the "ARCHS[@]: unbound variable" error after setting the iOS Simulator SDK to arm64 and who can build for a real device (also for Any IOS Device(arm64)) but can't build the Simulator. I solved my problem following the answer from the user called trishcode in this Stack Overflow post:

https://stackoverflow.com/questions/63607158/xcode-12-building-for-ios-simulator-but-linking-in-object-file-built-for-ios

What you need to do is:
  1. Remove what you did earlier, you MUST NOT set the iOS Simulator SDK to arm64,

  2. Set the VALIDARCHS variable with an empty value using a User-Defined build setting, you must set this in the project not in the target (in the main project and Pods project if you are using CocoaPods).

  3. Clean and build the project with a Simulator selected (I used iPhone 11).

    • The build will fail. After it fails, go to the project and delete the VALID

  4. ARCHS variable (in Pods project too).
  5. Check that the VALIDARCHS variable is not present in any project or target. Check the main project and the Pods project. Even though you set the VALIDARCHS variable in the projects, check the targets too because when I deleted it from the projects, the variable was still present in the targets. Like I said, remove VALIDARCHS in both the projects and the targets.

  6. After all the VALID

  7. ARCHS variables have been deleted, build the project again with a Simulator selected and it should build without the error of "ARCHS[@]: unbound variable".
Please check the Stack Overflow post for a better explanation of the solution.

Good luck.
Code Block
xcodebuild -configuration "Release" -scheme "${TARGETS_NAME}" -arch arm64 -arch armv7 -sdk "iphoneos"

@mvl-dxie answer helped me! and its the only thing that worked, thanks man!
Applying the following myProjectSettings.xcconfig settings to the Project Configurations has fixed the issue in my builds and still allows additional .xcconfig settings to be applied to individual targets within the Project. This explicitly sets the architectures for the iphoneos and iphonesimulator Xcode settings that are associated with ARCHS , VALIDARCHS , and EXCLUDEDARCHS.

Code Block
EXCLUDED_ARCHS[sdk=iphoneos*] = x86_64
EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64
ARCHS[sdk=iphoneos*] = arm64
ARCHS[sdk=iphonesimulator*] = x86_64
VALID_ARCHS[sdk=iphoneos*] = arm64
VALID_ARCHS[sdk=iphonesimulator*] = x86_64


NOTE: More architectures (e.g. armv7, armv7s, arm64e, etc) could be added to each of these settings for your build environment. My specific build intel based macOS environment does not include additional architecture because some third party binary frameworks don't include extra architectures.
Removing VALID_ARCHS from the build settings (left over from my XCode11) and then excluding arm64 when building for the simulator solved this for me.
Same issue. Nothing has worked so far.
As mentioned in the previous replies, the issue appears to be Xcode 12's inclusion of arm64 arch in the iPhone simulator, thus causing a clash between iPhone and Simulator when they are being combined to create the fat library.

So I followed kai_kai and @chimcanhcutptit@gmail.com's recommendation below and appears to have solved the problem (I was able to run my library in both simulator and real device). Basically the solution is to exclude arm645 architecture from the iphone simulator. This could have an impact when testing on arm64 macs later on - or may be not.

Select the project or target -> Build Settings -> Excluded Architecture (if you can't see it make sure [All] properties are selected) and set the Excluded Architecture for 'Any iOS simulator SDK' -> 'arm64'.
My project used VALID_ARCHS.

Removing only that build setting in Xcode 12 made the app runnable on the simulator.

Removing VALID_ARCHS required first clearing out its setting values. Then I was able to delete the entry itself and successfully build and run on the sim.
Just adding some more info. Xcode 12.2 Beta Release Notes includes this note:

Swift Packages
Known Issues
Swift Packages may not respect the “Build Active Architecture Only” project build setting when you try to build universal binaries. (64344067)

Workaround: Use the “Any Mac”, “Any iOS Device (arm64)”, “Any watchOS Device”, or “Any tvOS Device” destination to build for all applicable devices.

I know it's kinda unrelated because it's Xcode 12.2 (which none of us is probably using yet), and it's related to Swift Packages, but maybe this is also the case on Xcode 12 GM and non-Swift Package builds.
@chimcanhcutptit@gmail.com sloved my problem,thank you
For a general short term solution to this issue, the exclusion of arm64 arch needs to be specifically tied to iOS Simulator platform build.

If solution is not tied to iOS Simulator platform, you are telling Xcode to never build for the arm64 arch.

This solution doesn't work for me since I need to distribute FAT framework with all the iOS archs and all the iOS Simulator archs.

The newer Xcode 12 is treating arm64 as an iOS Simulator architecture as well as a legacy iOS architecture probably because MacOS Big Sur 11 running on an Arm64 based Mac will be running the iOS Simulator on arm64... But the Xcode folks didn't appear to think thru the affects.

Xcode 12 UX needs to be able to differentiate arm64 iOS Simulator from arm64 iOS in a better way. The generated binary need to include extra metadata so linker can tell choose the correct arch within a FAT library framework without displaying error because it chose unwisely.