You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a framework has a dependency that has resources such as CoreData files, using SPM in Xcode via Project->Swift Packages places the bundle in Products->Debug-iphonesimulator instead of Products->Debug-iphonesimulator->PROJECTNAME.framework causing the framework to crash at runtime when testing.
Everything works correctly if you open "Package.swift" instead of the xcodeproj file.
The workaround is placing a run script in Build Phases->Run Script:
if [ -d"$BUILD_DIR/Debug-iphonesimulator/" ]; thencp -r$BUILD_DIR/Debug-iphonesimulator/*.bundle$BUILD_DIR/Debug-iphonesimulator/ParseCareKit.framework/
fi
This is important when using code integration on a framework that's building from an Xcode project. The issue was discovered in my CareKit PR [here|carekit-apple/CareKit#543 (comment).]
The problem doesn't occur when running an app in Xcode instead of Framework.
Below is file produced by SPM:
importclassFoundation.BundleprivateclassBundleFinder {}
extensionFoundation.Bundle {
/// Returns the resource bundle associated with the current Swift module.staticvarmodule: Bundle = {
letbundleName = "CareKit_CareKitStore"letcandidates = [
// Bundle should be present here when the package is linked into an App.Bundle.main.resourceURL,
// Bundle should be present here when the package is linked into a framework.Bundle(for: BundleFinder.self).resourceURL,
// For command-line tools.Bundle.main.bundleURL,
]
forcandidateincandidates {
letbundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
ifletbundle = bundlePath.flatMap(Bundle.init(url:)) {
returnbundle
}
}
fatalError("unabletofindbundlenamedCareKit_CareKitStore")
}()
}
And the candidate locations:
(lldb) poBundle.main.resourceURL
▿ Optional<URL>
▿ some : file:///Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Agents/
- _url : file:///Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Agents/(lldb) po Bundle(for: BundleFinder.self).resourceURL
▿ Optional<URL>
▿ some : file:///Users/coreybaker/Documents/Xcode_Projects/ParseCareKit/DerivedData/Build/Products/Debug-iphonesimulator/ParseCareKit.framework/
- _url : file:///Users/coreybaker/Documents/Xcode_Projects/ParseCareKit/DerivedData/Build/Products/Debug-iphonesimulator/ParseCareKit.framework/(lldb) po Bundle.main.bundleURL
▿ file:///Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Agents/
- _url : file:///Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Agents/
Looking at the attached pictures shows that the bundle isn't placed in one of the candidate folders.
The text was updated successfully, but these errors were encountered:
Attachment: Download
Environment
Xcode 12.4
macOS Catalina
Additional Detail from JIRA
md5: 369f1f32d09f19ea3c796655d5a88776
Issue Description:
When a framework has a dependency that has resources such as CoreData files, using SPM in Xcode via Project->Swift Packages places the bundle in Products->Debug-iphonesimulator instead of Products->Debug-iphonesimulator->PROJECTNAME.framework causing the framework to crash at runtime when testing.
Everything works correctly if you open "Package.swift" instead of the xcodeproj file.
The workaround is placing a run script in Build Phases->Run Script:
This is important when using code integration on a framework that's building from an Xcode project. The issue was discovered in my CareKit PR [here|carekit-apple/CareKit#543 (comment).]
The problem doesn't occur when running an app in Xcode instead of Framework.
Below is file produced by SPM:
And the candidate locations:
Looking at the attached pictures shows that the bundle isn't placed in one of the candidate folders.
The text was updated successfully, but these errors were encountered: