143

I cannot run my app on simulators anymore. Online suggested that I edit my project.pbxproj, but that does not appear to work. How do I reclaim the ability to run my project on my simulator (and remain able to do so on a device)? I am working on another project that uses many of the same frameworks, but it runs on a simulator. What would cause a similar framework to work in one project but not in another?

Leo Dabus
  • 198,248
  • 51
  • 423
  • 494
michaeldebo
  • 2,107
  • 3
  • 9
  • 17

11 Answers11

433

Xcode 12.3

In my case I solved this problem by simply setting Validate Workspace to Yes in the Build Settings tab

enter image description here

RunesReader
  • 4,691
  • 1
  • 8
  • 11
  • 81
    No doubt it is +1 from me, it saved me. But honestly, how do you people figure out how to fix this kind of issues?! What was your thought process? – interrupt Dec 16 '20 at 05:42
  • This was a life saver. Unfortunately this now shows a warning in the project as well, does anyone else have that as well? It's fine for now, but I'd like to eventually get rid of that, too. – Gero Dec 16 '20 at 07:42
  • 3
    It saved me too. It happened as i updated XCode to 12.3, but this fixes it – Stoyan Dec 16 '20 at 08:44
  • Works for me! But when I change to NO again it still works. Any idea? – Hen Shabat Dec 16 '20 at 09:28
  • Absolutelly brilliant! Buy still yeah, figuring this out was too random! – Petrescu Silviu Dec 16 '20 at 09:51
  • 1
    @HenShabat it seems that toggling the value it writes it to .pbxproj file which seems to be sufficient for Xcode to stop complaining. – mijokaliger Dec 16 '20 at 10:46
  • what was the thought process? How did you figure out that? It really worked for me. Thanks – Habib Ali Dec 16 '20 at 12:22
  • It works like a charm! Thanks! I've started separation of universal library into arm64 and x86_64 versions and then found this solution. – razor28 Dec 17 '20 at 08:53
  • 11
    Can someone explain why it works? When I changed `Validate Workspace` then my errors became warnings. That's crazy and unpredictable. Maybe it doesn't solve the core issue but we just found another bug in Xcode? – Michal Cichon Dec 17 '20 at 11:58
  • @HenShabat Answering your question, when you change to YES and then to NO again, then you will have `VALIDATE_WORKSPACE = NO;` inside your pbxproj file instead of nothing which falls back to "NO". I guess the building process fails at some point if this flag is not set (no YES nor NO in the project file). – Michal Cichon Dec 17 '20 at 12:46
  • Works for me too. It's a magic... – BigLiao Dec 17 '20 at 13:02
  • This is the most magical solution to a SO problem I've seen this year, thank you!!! – Kyle Liu Dec 17 '20 at 18:24
  • 1
    Looking at the options for Validate Workspace, we have No, Yes, and Yes (Error), setting Validate Workspace to Yes (Error) gives me this error, setting it to Yes gives me a warning, setting it to No ignores this issue completely. Seems to me that they changed the default value to Yes (Error). – user8127814 Dec 18 '20 at 16:30
  • 1
    I had to switch it from `No` to `Yes` then back to `No` again for it to work. I'm not updating Xcode anymore...Every time I do I have to waste at least a day trying to fix my projects so they compile again. – RcoderNY Dec 18 '20 at 21:50
  • 7
    The root issue is likely that your workspace is invalid, as you are linking a pre-built "fat" .framework, containing both an iOS and a iOS simulator slice, rather than a .xcframework. The former is unsupported by Xcode. In Xcode 12.3, since frameworks are now validated against this criteria, and the Verify Workspace default setting changed to "Yes (Error)" (?), you see this error. Regarding .xcframework, see my answer https://stackoverflow.com/a/65417883/3727099 for more details. – guru_meditator Dec 23 '20 at 01:24
  • 1
    Life saver. Apple is just trouble maker. – neobie Dec 23 '20 at 14:20
  • @RunesReader after doing the mentioned change, I am getting an error : `Swift compiler error: Switch must be exhaustive` can anyone help me with this? – Ragesh Pikalmunde Dec 29 '20 at 08:16
  • @RunesReader Genius – ΩlostA Jan 06 '21 at 18:17
  • Great! **It worked!!** It saves my time. I tried various process but couldn’t solve by myself. – Ahsan Ullah Rasel Jan 13 '21 at 04:40
  • It works!!!!! for me. Thanks stranger.... – Torongo Mar 16 '21 at 06:48
  • 1
    Absolutely marvellous. I am switching from XCode 12.2 directly to 12.4 and this was also the solution to my problem. Thanks! – virusss8 Apr 01 '21 at 12:13
98

No doubt that the fix in case of Xcode 12.3 is to setup the Validate Workspace property in the target's build setting. However if you check the diff after this change, the reason of the build error is the missing parameter (VALIDATE_WORKSPACE) from the project file, not the value of the parameter. So you don't need the value to be YES. You need to add the value to the project settings and you can leave it on the default value (NO). At the first time, it shows up in the Build Settings with NO, but only because that is the default value of the missing parameter.

TLDR; Without changing your project setup, go to your target's build settings, find "Validate Workspace", set it to YES, then set back to NO.

flyerz
  • 1,585
  • 10
  • 7
  • 7
    Yes! This is correct, I had to switch it from No to Yes then back to No again for it to work. I'm not updating Xcode anymore...Every time I do I have to waste at least a day trying to fix my projects so they compile again. – RcoderNY Dec 18 '20 at 21:59
15

Use a .xcframework rather than a "fat" .framework containing an iOS and iOS simulator slice. This also obviates the need to use a build phase to strip the iOS simulator slice when building for the App Store.

"Fat" frameworks, which are typically created using lipo as they cannot be built directly by Xcode, are not supported (source: Developer Technical Support Apple Developer forum). .xcframework is the only supported mechanism to ship a single framework supporting both iOS and the iOS simulator.

Also .xframework's is the only supported way to ship a binary Swift framework (source: Developer Technical Support on Apple Developer forum).

In Xcode 12.3, the fact that "fat" frameworks are non supported is enforced, as Xcode verifies the frameworks during build, which is why a lot of projects suddenly started to see build errors.

guru_meditator
  • 424
  • 5
  • 10
10

Most answers here are for consumers of universal binaries to work around the new restrictions. But, as in noted elsewhere, it's time to migrate to Apple's XCFramework format for framework authors.

If you were running a custom build script to create universal binary before with an aggregate target and lipo, it's straightforward to migrate to producing .xcframework files

First, in build settings make sure "Build Libraries for Distribution" (BUILD_LIBRARY_FOR_DISTRIBUTION) is set to YES

Then, replace your existing aggregate target build script that used lipo with something like the following which is simple for showing how to make "release" frameworks only:

# Universal Script

set -e

FRAMEWORK_NAME="your_framework_name"
IOS_SCHEME_NAME="your_scheme_name"

if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi

SIMULATOR_ARCHIVE_PATH="${SRCROOT}/build/${FRAMEWORK_NAME}-iphonesimulator.xcarchive"
DEVICE_ARCHIVE_PATH="${SRCROOT}/build/${FRAMEWORK_NAME}-iphoneos.xcarchive"

OUTPUT_DIR="${SRCROOT}/framework_out_universal/"

# Simulator xcarchieve
xcodebuild archive \
  -scheme ${IOS_SCHEME_NAME} \
  -archivePath ${SIMULATOR_ARCHIVE_PATH} \
  -configuration Release \
  -sdk iphonesimulator \
  SKIP_INSTALL=NO

# Device xcarchieve
xcodebuild archive \
  -scheme ${IOS_SCHEME_NAME} \
  -archivePath ${DEVICE_ARCHIVE_PATH} \
  -sdk iphoneos \
  -configuration Release \
  SKIP_INSTALL=NO

# Clean up old output directory
rm -rf "${OUTPUT_DIR}"

# Create xcframwork combine of all frameworks
xcodebuild -create-xcframework \
  -framework ${SIMULATOR_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
  -framework ${DEVICE_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
  -output ${OUTPUT_DIR}/${FRAMEWORK_NAME}.xcframework

# Delete the most recent build.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi

You can tweak the above to have different output dirs, different deletion behavior, support multiple configurations (Release vs Debug) but this works for me.

Finally, as a one time step, delete the your_framework_name.framework universal binary that caused you the error as mention in this project. Copy the newly built your_framework_name.xcframework and add it to the project and the error should go away.

mistahenry
  • 8,064
  • 3
  • 22
  • 36
9

It happened to me when I added my custom framework into the project and after I updated my Xcode, I encountered the same issue.

Solution : under build settings in project search for Validate workspace Just change to yes which is by default set to no

enter image description here

Espresso
  • 1,495
  • 3
  • 5
  • 17
5

possible reason would be

  1. framework which you are using may not be built for simulator architecture(x86_64), you can check the compatibility by going to framework folder (framework_name.framework --> modules --->framework_name.swiiftModule-->) in this path you should see arm/i386/x86_64 support files
  2. if you have updated to new Xcode, the frameworks you are using are not compatible to the newer compiler version, so vendor needs to share the recent compatible one, in this case you will not be able to run on both device and simulator
nca
  • 177
  • 2
  • 11
3

Xcode 12.3 is full of issues. Your options are :

  1. Use legacy build system or
  2. Downgrade to 12.2 Not sure how Apple release such a buggy product
Gal Blank
  • 1,987
  • 2
  • 15
  • 18
0

I suppose the framework you are linking was built only for arm architecture. You won't be able to run it in a simulator. You will need an author of the framework to build a "universal framework".

shim
  • 7,170
  • 10
  • 62
  • 95
Karol
  • 136
  • 1
  • 2
  • 8
  • 1
    The framework is a compilation of cocoapods that consist mostly of Firebase pods along with SDWebImage and a few others. Do I have to revert to Xcode 11.3 or use a legacy version? Why did this error start happening when it worked fine for over a year? – michaeldebo Aug 05 '20 at 15:39
0

To be honest, the only approach that you guys should follow is to convert .framework to .xcframework, as this is what Apple enforces from XCode version 12.3 and above. Validating workspace and other quick fixes may be temporary and cause problems in the future - like archiving the app for appstore release or testflight.

To convert .framework to .xcframework follow the steps described in the article, starting from paragraph Commands: https://medium.com/strava-engineering/convert-a-universal-fat-framework-to-an-xcframework-39e33b7bd861

-1

I ran in this error on Xcode v12.3 and Universal(fat) Framework(.framework)

Building for iOS Simulator, but the linked and embedded framework was built for iOS + iOS Simulator.

Solution 1: is Toggle/Toggle Validate Workspace(not default)

Solution 2: use XCFramework[About]

yoAlex5
  • 13,571
  • 5
  • 105
  • 98
-5

If you are new to Xcode and using Xcode just to launch emulator to run appium tool the above steps might be complex. Just use xcode version less than 11 for beginners.

This link helps to download xcode 10.3

Xcode10.3

If you try to download from AppStore we need to have free storage up to 40 GB the above `xip file will won't cause storage errors.

You can Thank me later if this works!!