Xcode编译报错No architectures to compile for,请求排查问题原因
Hey there, let's break down and fix this architecture mismatch issue you're facing!
What's causing the error?
The problem is straightforward: your project is set to compile for the arm64 architecture (configured in ARCHS), but your VALID_ARCHS list only includes armv6 and armv7. Since there's no overlap between these two sets, the compiler can't figure out which architecture to build for—hence the frustrating error.
Step-by-step fixes
Here are a few actionable ways to resolve this, depending on your project's needs:
Add arm64 to VALID_ARCHS
- Open your Xcode project, select your target, and switch to the Build Settings tab.
- Search for
VALID_ARCHS(you may need to toggle from "Basic" to "All" settings to see it). - Update the value to include
arm64, making it:armv6 armv7 arm64. - Confirm your
ARCHSsetting still includesarm64(it already does in your case) so the two lists have overlapping architectures.
Simplify VALID_ARCHS for modern projects
If you don't need to support extremely old devices (armv6 is practically obsolete now), you can:- Set
VALID_ARCHStoarmv7 arm64. - Ensure
ARCHSis set to a compatible option likeStandard architectures (armv7, arm64)or justarm64if you only target newer iOS devices.
- Set
Remove VALID_ARCHS entirely (recommended for newer Xcode versions)
Recent Xcode versions handle valid architectures automatically based on yourARCHSsetting and target iOS version. You can:- Select the
VALID_ARCHSrow in Build Settings. - Press the delete key to remove the setting entirely.
- Clean your project (press
Cmd + Shift + K) and rebuild—this also clears any stale build cache that might cause issues.
- Select the
Extra tips
- If you're using CocoaPods, double-check that your Pods targets have matching architecture settings. You might need to run
pod installagain after updating your project's config. - After making changes, it's a good idea to delete your derived data (Xcode > Settings > Locations > Derived Data > Delete) to avoid any lingering build artifacts causing unexpected problems.
内容的提问来源于stack exchange,提问作者user979331

