PC パソコン

How to Fix “does not contain an archive” in Xcode Previews

When a SwiftUI preview loads a target that depends on a static library, Xcode may report “does not contain an archive” even though the normal project build succeeds. Apple fixed an issue in Xcode 26 where Previews mishandled some static libraries and produced this diagnostic. This guide explains how to distinguish that known Preview issue from an actually damaged library and how to resolve it safely.

Representative error log

Xcode Previews could not build the selected scheme
error: '/path/to/libExample.a' does not contain an archive

The library name and path vary by project. The important signature is that the error appears while SwiftUI Previews is preparing a target and identifies a static library, usually a .a file, as not containing an archive.

Cause

Apple’s Xcode 26 release notes list a resolved issue where Previews produced a “does not contain an archive” error for static libraries. A valid .a file could therefore be rejected by the Preview build pipeline in Xcode versions earlier than 26.

Important: Apple’s fix specifically concerns Xcode Previews. If the same message appears during a command-line build or ordinary link step, first investigate a corrupt file, an incorrect file format, or an incomplete build artifact.

Affected conditions and versions

  • You are using a version of Xcode earlier than 26.
  • The target rendered by SwiftUI Previews directly or indirectly depends on a static library.
  • A normal Build may succeed while preparation of the preview fails.
  • The diagnostic contains does not contain an archive.

Apple does not identify the exact Xcode release in which the defect was introduced. Xcode 26 is the officially documented version containing the fix.

Recommended resolution

  1. Update to Xcode 26 or later. Prefer a stable Apple release when possible.
  2. Confirm which Xcode is active. If several versions are installed, make sure the GUI and command-line tools point to the intended installation.
xcodebuild -version
xcode-select -p
  1. Quit and reopen Xcode, then reopen the project or workspace.
  2. Choose Product > Clean Build Folder, then resume the preview.
  3. Only if the problem remains, remove DerivedData for the affected project and rebuild. For a Swift Package Manager dependency, also verify package resolution and the package cache.

If the problem still reproduces on Xcode 26 or later, Apple asks developers to file feedback and attach the static library for analysis. Follow your organization’s data-handling policy before submitting a library that may contain proprietary code.

Alternatives when an upgrade is not possible

These are diagnostic steps or temporary workarounds, not replacements for Apple’s fix:

  • Provide a preview-only mock and temporarily exclude the affected static-library dependency from the Preview build.
  • Place calls to the library behind a thin wrapper and substitute a stub when rendering previews.
  • Check whether the file is actually an ar archive with the following command.
xcrun ar -t /path/to/libExample.a

If the command prints the archive members, the file is at least readable as an ar archive. If it fails, do not assume the Xcode Preview bug is responsible. Rebuild the library for the correct SDK, platform, and architecture.

How to verify the fix

  1. Run xcodebuild -version and confirm that Xcode 26 or later is active.
  2. Perform a normal Build and verify that the static library links successfully.
  3. Click Resume in the SwiftUI preview.
  4. Confirm that does not contain an archive no longer appears and the preview renders.
  5. Launch the relevant screen in a simulator or on a device to ensure that preview-specific changes did not break runtime dependencies.

Important notes

  • A .a extension alone does not prove that the file is a valid static library. A failed download or an HTML error page saved under the wrong extension can produce a similar symptom.
  • An architecture mismatch normally produces a different diagnostic, such as building for ... but attempting to link. Do not treat the two problems as identical.
  • DerivedData is safe to regenerate, but deleting it repeatedly should not be the first step. Update Xcode and inspect the actual file first.
  • If xcrun ar -t fails for the library, upgrading Xcode will not repair the artifact.

Summary

If does not contain an archive occurs only in Xcode Previews for a static library, the project may be hitting the Preview handling bug fixed in Xcode 26. Updating to Xcode 26 or later is the recommended solution. If the normal build fails too, inspect the file with xcrun ar -t and rule out corruption or a format mismatch before treating it as the Preview-specific issue.

Official references