I've been dealing with this problem for HOURS and your description has helped me come up with the 'solution'.
TLDR: (temporarily) change the dynamic package to static during development, then switch back to dynamic before deploying.
Obviously this only works if you control the client package.
I'm not expert, but here's my explanation:
Since the client package is dynamic, it's technically not supposed to be linked/accessed until runtime. And I don't think SwiftUI previews count as 'runtime'.
So, when the SwiftUI preview tries to access code from a dynamic library, it's not available.
This problem does NOT occur in an Xcode project because you have to embed the packages in the main target, which I guess solves the problem.
Unfortunately, there's no option to embed (even temporarily) in a swift package. So there's no way to allow the SwiftUI preview to gain access to the third party dynamic libraries.
When I commented out the dynamic declaration in the package.swift file (converting the dynamic library to static), the previews in my swift package that used the dynamic (now static) library started working. I'll likely write a script into my CI/CD to uncomment the line (and switch the package back to dynamic) before deploying so I don't forget.
I hope this helps. And shame on Apple for knowing about this problem for YEARS and ignoring it.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: