Xcode报错No such module:导入框架后模拟器正常、归档失败求解决
Hey there, I’ve seen this exact issue pop up a lot when archiving projects with custom frameworks in Xcode 9/Swift 3—let’s walk through the most reliable fixes to get your archive working:
Simulators use x86_64/i386 architectures, but archiving for Generic iOS Devices targets arm64/armv7 (device-specific architectures). If your framework only includes simulator builds, you’ll hit that "No such module" error during archiving.
- Right-click your framework in Xcode, select
Show in Finderto locate it. - Open Terminal, navigate to the framework’s folder, and run:
lipo -info YourFrameworkName.framework/YourFrameworkName - If the output doesn’t list
arm64orarmv7, you need a universal framework (combines simulator and device builds). You can either request one from the framework provider, or compile it yourself by building for simulator and device separately, then merging the binaries withlipo -create.
Incorrect search paths or build options are often the culprit:
- Framework Search Paths: Go to your target’s
Build Settings→Search Paths→Framework Search Paths. Ensure the path to your framework is correct (use relative paths like$(SRCROOT)/Frameworksinstead of absolute paths) and set torecursiveso Xcode finds nested frameworks. - Always Embed Swift Standard Libraries: If your framework is written in Swift, enable this option under
Build Settings→Build Options. Archiving requires these libraries to link properly. - Valid Architectures: Double-check
Build Settings→Architectures→Valid Architecturesincludesarm64andarmv7(Xcode 9 should have these by default, but sometimes they get accidentally removed).
Linking a framework isn’t enough—you need to embed it for archiving:
- Go to your target’s
Generaltab. Look underEmbedded Binariesand make sure your framework is listed here. If it’s only inLinked Frameworks and Libraries, add it toEmbedded Binaries(this will auto-add it to the linked list too). - Check code signing: For third-party frameworks, ensure their signature is compatible with your project’s code signing identity. If you built the framework yourself, make sure your archive uses a valid development or distribution certificate.
Xcode’s cached build data can cause weird inconsistencies between simulator and archive builds:
- Hold the
Optionkey and go toProduct→Clean Build Folder(this clears more data than a regular Clean). - Close Xcode, then delete your Derived Data folder: Find it via
Xcode→Preferences→Locations, click the arrow next to the Derived Data path, and delete the entire folder. - Reopen Xcode, build for the simulator first to confirm everything works, then switch to Generic iOS Devices and try archiving again.
- Double-check that your
import YourFrameworkstatement uses the correct case—Swift is case-sensitive, so a typo here can cause module not found errors during archiving (even if it works in the simulator). - If you’re using a static framework, add
-ObjCor-all_loadtoBuild Settings→Other Linker Flagsto ensure all framework symbols are linked properly during archiving.
内容的提问来源于stack exchange,提问作者IMan Merzaie

