Building for iOS Simulator, but the linked framework '.framework' was built for iOS
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Building an application for the iOS Simulator can sometimes present challenges, particularly when dealing with frameworks that are compiled for the actual iOS device architecture rather than the simulator. A common issue developers encounter is the error message: "Building for iOS Simulator, but the linked framework '****.framework' was built for iOS". This article addresses the causes of this problem and provides some technical guidance for troubleshooting and resolving it.
Understanding the iOS Simulator vs. iOS Device Architecture
When developing iOS applications using Xcode, the binaries need to target different architectures depending on the usage context:
- iOS Devices typically utilize ARM architectures (
armv7,arm64). - iOS Simulator relies on x86_64 or Apple Silicon (for newer Mac M1 or M2 chips) architectures.
Frameworks compiled for an iOS device cannot natively run on the iOS Simulator due to these architecture differences.
Common Causes of the Error
- Framework Architecture Mismatch:
- The framework you're attempting to link against your application is compiled only for the ARM architecture and lacks the necessary slices for the simulator.
- Incompatible Build Settings:
- Incorrect configuration in Xcode build settings that do not target the simulator's architecture.
- Static Libraries:
- Use of static libraries that are not universal and contain only device-specific architectures.
Solutions and Workarounds
Creating a Universal Framework
A universal (or fat) framework bundles multiple architectures into a single binary. This allows the same framework to be used on both iOS devices and the simulator.
Steps to Create a Universal Framework:
- Modify Build Settings:
- Open the framework's project in Xcode.
- Go to
Build Settings. - Set
Build Active Architecture OnlytoNofor both Debug and Release configurations.
- Build for Both Architectures:
- Use the
xcodebuildCLI to build your framework for different architectures: - Navigate to the
builddirectory. - Use
lipoto create a universal binary: - For the device:
- For the simulator:
- Drag the
YourFramework.xcframeworkto your Xcode project’sFrameworksfolder.
- Static vs Dynamic Libraries: Prefer dynamic libraries for better compatibility unless static libraries provide significant advantages.
- CocoaPods or Carthage: Check if your package manager supports XCFrameworks to automate integration.
- Podspecs and Package.swift: Ensure they define appropriate architecture support for simulator builds.
Related reading
- Building iOS applications using xcodebuild without codesign
- Building Kivy Android app with Tensorflow
- Bundle ID Suffix? What is it?
- Bundle.main.pathforResourceofTypeinDirectory returns nil
- Bundle.main.pathforResourceofTypeinDirectory returns nil
- Button border with corner radius in Swift UI
- Button border with corner radius in Swift UI
- CABasicAnimation resets to initial value after animation completes
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.