Context
We build a closed source Framework containing a few dependencies which are imported using Cocoapods. The framework is then distributed as a pod and embedded into various internal and external projects.
I have developed a private Package (SPM) that is meant to be consumed by the Framework. It is imported to the Framework's Xcode workspace as a Swift Package Dependency (along with the other Cocoapods dependencies). The package contains resources (.xib, images, localizedStrings) which are all private - the package's public API only exposes a UIViewController that itself uses all these resources (package accesses resources through Bundle.module
).
The Framework's Xcode project also contains a target (a test iOS App) for simply importing and running the framework. Everything works perfectly. The test app is able to run the framework (import Library
) and when the framework loads the UIViewController from the Swift Package (which in turn loads all the resources) everything display without trouble.
Problem
The problem comes when I archive the library. The .bundle
from the Swift Package doesn't get copied into the resulting xcarchive. This leads to a crash happening at runtime when we run our framework inside other apps.
Fatal error: unable to find bundle named SPMPackage_Module
My understanding
This crash happens because the app isn't able to find the bundle when calling Bundle.module
. This led me to find that the bundle indeed wasn't anywhere to be found in the Framework.
Our script archives the library (xcodebuild archive ...
) on both iphonesimulator
and iphoneos
platforms and then packages the result as a universal framework. I would expect the package's bundle to be part of the archive but it's not.
Workaround
I have found the bundle in the DerivedData folder:
DerivedData/Intermediates.noindex/ArchiveIntermediates/OurFramework/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/SPMPackage_Module.bundle
There is also an alias to that file in there:
DerivedData/Intermediates.noindex/ArchiveIntermediates/OurFramework/BuildProductsPath/Release-iphoneos/SPMPackage_Module.bundle
If I take that bundle and copy it into the Framework, then everything runs fine.
Questions
- Is this a bug or am I missing a step when archiving my library? (That would lead to the swift package's bundle not being copied into the resulting archive)
- Any better workaround that what is mentioned above?
Thanks!