We have a Mac app that uses several private GitHub hosted Swift Package Manager packages. The app builds file from within Xcode 13.4 whether the builds are Debug (Run) or Release (Archive).
However, when built via xcodebuild in Terminal, we get Error: No such module [our package] on an import [our package] statement in a Swift source file. I've tried many variants of the xcodebuild archive command, but nothing seems to fix the issue. We have two other nearly identical projects that work fine with the packages and build scripts. The command looks like:
xcodebuild \
-sdk macosx
-target "$target" \
-scheme "$scheme" \
-archivePath "$archivePath" \
-destination "generic/platform=macOS" \
archive
or
xcodebuild \
-scheme "$scheme" \
-archivePath "$archivePath" \
-destination "generic/platform=macOS" \
archive
Again, the app builds fine from within Xcode 100% of the time.
I'm sure we're using the latest tools: xcodebuild -version returns "Xcode 13.4 Build version 13F17a"
I suspect this either has something to do with the Swift packages all referencing a shared package [our package], but I checked the project and Package.swift files and they all use exactly the same name, urls, and capitalization, and the dependencies seem ok, or perhaps it's because we use Schemes to build the apps in three different flavors - dev, qa, and production - all with unique bundleIDs? We're using branch-based .package dependencies if that matters:
.package(name: "OurPackage", url: "https://github.com/account/OurPackage", Package.Dependency.Requirement.branch("main")),
I'd appreciate any suggestions on how to debug/resolve this. I've tried creating a smaller reproducible demo project but of course they all work fine.
Edit: Per a suggestion on iOS-developers, I ran xcodebuild -resolvePackageDependencies and all of the packages downloaded just fine. No errors.
With the help of Apple engineers during the WWDC, we determined that my primary problem was that I used both --target and --scheme parameters to xcodebuild. Turns out --scheme alone works much better. There was another problem in my bash script and xcodebuild didn't return errors well in that case, but that was a secondary issue.