I was in the process of switching over an existing framework to SwiftPM. It requires OpenCV as a binary dependency. Through incredible annoyance and plethora of crashes in xcframework and Xcode I managed to get OpenCV working in SwiftPM. It builds and runs correctly on device... fantastic.
But, as soon as I archive the project it fails due to missing OpenCV headers. Any ideas as to why? And to a fix? It works fine build on device, just not archiving.
Are you able to share more information about the package(s) involved, e.g. their manifests? This thread on the SwiftPM slack could also be relevant: Slack
So after a ton of trial and error I was able to get it sorted out, but this feels like a bug. The issue appears to be the headers are not correctly copied or the path is incorrect from the XCFramework during the archiving process. (Maybe xcframework cli tool is buggy?) Although Swift PM normally recognize the OpenCV headers from XCFramework, builds correctly, and runs correctly.
I had to manually copy the opencv headers for the target while retaining the correct directory structure and include them. But the exact same headers and structure exists inside XCFramework. So this feels like a big bug to me.
I included the working package.
I didn't take a look at the slack thread yet, but if I get time I will.
Going off on a rant here. So this actually doesn't work. Everything works up to submitting to the App Store.
The App Store refuses to accept the archive about some nonsense that opencv2 is not permitted because it contains a standalone library or executable. Yet the same framework works if it's embedded in a regular project.....
I've wasted way too much time trying to get binary targets to work in Swift PM. I've tried every iteration under the sun. Honestly, it feels like a poorly built feature that just doesn't work and is so hacky it would probably randomly break one day for no reason other than Apple's crappy App Store.
Does opencv2.xcframework contain static libraries? We do have a known issue about static libraries / frameworks being embedded in the app bundle incorrectly.
Is there an open bug report on this issue? I'm having a (probably) similar issue where my static frameworks are getting thrown into my other target's install locations (QuickLook Plugin and Safari App Extension)
This seems to be resolved in Xcode 12.5 beta 2. I was able to remove the need for having my binary dependency exposed as its own product library and could instead include it as a target to my library.