Skip to content
Latchkey

Swift "Compiling for iOS ... but module was built for ..." arch mismatch in CI

The compiler is building for one platform/architecture but a dependency module was compiled for another. This happens when a cached or binary module does not match the current destination or a stale .build mixes platforms.

What this error means

Build fails with "error: Compiling for iOS X, but module 'Y' was built for iOS Z" or a "module compiled for a different architecture" variant.

swift
error: Compiling for iOS 15.0, but module 'Networking' was built for iOS 17.0
error: could not build Objective-C module 'Networking'

Common causes

A stale build directory mixes platforms

A .build or DerivedData directory restored from a different destination holds modules compiled for another deployment target or architecture.

A binary dependency built for a different target

A precompiled xcframework or binary target module was built for a platform/arch that does not match the current build.

How to fix it

Clean the build and rebuild for one destination

  1. Remove the stale .build (and DerivedData if using Xcode).
  2. Rebuild with a single, explicit destination or deployment target.
  3. Confirm all modules compile for the same platform.
Terminal
rm -rf .build
swift build

Match the deployment target across the graph

Set a consistent platform minimum so dependency modules and app code target the same iOS version.

Package.swift
platforms: [.iOS(.v15)],

How to prevent it

  • Key any build cache on the destination/platform so mismatched artifacts are not reused.
  • Keep platforms: consistent between the app and its packages.
  • Rebuild binary dependencies for every platform you ship.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →