ProductSDK — xcframework that will be integrated by clients in their host apps (iOS platform).
BusinessLogic — dependency of ProductSDK that shouldn't be exposed to developers integrating ProductSDK
What I tried
Added BusinessLogic.xcframework to ProductSDK.
Used @_implementationOnly import BusinessLogic to hide BusinessLogic.
Then archived and created final ProductSDK.xcframework.
Problem
When ProductSDK.xcframework is added to host application, I can import ProductSDK. import BusinessLogic returns no such module, which is expected.
When the app is run, it works on simulator, but it crashes in runtime on real device with an error: "BusinessLogic image cannot be found".
Question
How to add BusinessLogic dependency to ProductSDK xcframework? Is it even possible for iOS platform?
Is BusinessLogic linked dynamically or statically? If it’s the former, this isn’t supported on iOS because iOS does not support nested frameworks. To make this work dynamically you’d have to give your clients two separate XCFrameworks, ProductSDK and BusinessLogic, both of which get added to the app’s top-level Frameworks directory, and that runs counter to your goal of hiding BusinessLogic from your clients.
Thanks for the answer @eskimo. BusinessLogic is a xcframework. Solution to give both frameworks to clients is not possible.
Is it possible to statically link BusinessLogic.xcfamework in ProductSDK, so clients only need to add ProductSDK.xcframework in their app? If it's possible with xcframework, how to do it?
An XCFramework can wrap a framework, a ‘naked’ dynamic library, or a static library. So, if you can build BusinessLogic as a static library and wrap it in an XCFramework, you should be able to statically link it into ProductSDK.
Asking on a related note. We have a dynamic xcframework that has two dependencies that are both static frameworks themselves. They are embedded into the top level framework.
xcframework A
-- static xcframework dependency B
-- static xcframework dependency C
This has worked fine, until one of the dependencies added localizations and resources into their SDK. We add the localization / asset resources of dependency C under "Copy Bundle Resources" of our main application, which works for building locally, but now those assets are exposed in the binary archive of xcframework A.
This has resulted in errors thrown during the AppStore validation process.
Is this usecase supported, or do we need to find another way to solve our problem?
@eskimo thanks for your inputs. I am working on something similar. With respect to your previous answer I have few questions:
What do you mean by 'naked' dynamic library?
I read here that umbrella frameworks are not supported in iOS, so by building business logic as a static library and wrapping up it in an XCFramework can we by-pass this?
If we start giving the BusinessLogic framework or any third party framework separately then it would be very inconvenient for the user to manually link all these frameworks. I was wondering can we create a SPM for binary link third party dependencies and give it for integration? Is that the Apple recommendation way?