I'm facing a strange issue where attempting to archive an application with xcodebuild produces an error where it can't find a specific module.
Below is a sample from the output from our CI/CD pipelines:
▸ Processing Info.plist ▸ Processing Watch app-Info.plist skipping copy phase strip, binary is code signed: /Users/[REDACTED]/Library/Developer/Xcode/DerivedData/App-hahppujjrqxvtqfuypdagaondkkd/Build/Intermediates.noindex/ArchiveIntermediates/app-Enterprise/IntermediateBuildFilesPath/UninstalledProducts/watchos/app Watch Extension.appex/app Watch Extension (in target 'Watch App' from project 'App') ❌ /Users/[REDACTED]/git/App/Classes/WebController.swift:10:8: no such module 'NetworkComponents' import NetworkComponents ^~~~~~~~~~~~~~~~~~~ ▸ Touching app\ Watch.app (in target 'Watch App' from project 'App') ▸ Linking Tools.o ▸ Linking NetworkComponents.o
I am unsure as to why this is occurring, but it does not do this when building/archiving with Xcode, only with the xcodebuild command. I am wondering if this could be a race condition of some sort or if the fact that it links NetworkComponents.o after trying to compile a class that imports the module has anything to do with it?
Some additional information:
- I am on Xcode 14.1 and Swift Package Manager 5.7.1
- The module it fails to find is a Swift Package Manager dependency
- Verified the issue is present on both an Intel-based Mac and a M1 Mac.
- It is the same module that it states it can't find after running the xcodebuild archive command each time and It is for the same file as well. Issue is consistent across multiple runs.
The following are the commands that are executed:
xcodebuild -resolvePackageDependencies -project TestProject.xcodeproj -scheme TestProject -scmProvider system
xcodebuild "-workspace" "/Users/[REDACTED]/Desktop/TestProject/TestProject.xcworkspace" " scheme" "TestProject" -allowProvisioningUpdates
xcodebuild "archive" "-workspace" "/Users/[REDACTED]/Desktop/TestProject/TestProject.xcworkspace" "-scheme" "TestProject" -allowProvisioningUpdates
When I clear all derived data and caches
(rm -rf ~/Library/Caches/org.swift.swiftpm/ and
rm -rf /Users/yalmatm/Library/Developer/Xcode/*) then the build will succeed the first time, but rerunning the third command to archive it will continue to produce the issue.