At work, we have a dependency that’s provided to us by a vendor as an XCFramework. They give us a separate XCFramework for each configuration in our app (Debug, Alpha, Beta, RC, Release).
Does anyone know of a good way to change the dependency being used depending on what configuration is being built? Perhaps there’s a config setting to do this? We do have separate xcconfig files for each configuration.
Xcode’s build phases don’t support configuration-based conditional linking, so you’ll have the resort to build settings and script build phases, to achieve that. Have you considered asking for a single version of the XCFramework that’s controlled at runtime? What’s the rationale behind a per-configuration binary?
Great question. We asked the vendor if they could use a single XCFramework. They said no. And unfortunately it’s out of our control.
Do you have any suggestions on build settings and/or build phase scripts I could use to accomplish this? I’ve tried searching around online but have come up short. Maybe there’s some way to use framework search paths or something? Or a build phase script that moves the correct XCFramework to a place that Xcode will then pull from?
So you need to play with the following build settings:
Framework search paths: You need to dynamically change the directory based on the configuration being built.
Swift compiler flags: To indicate that you want to link a framework or a library named X.
And if the binary is dynamic, you have to then add a script build phase that copies the right binary from within the XCFramework into the bundle so that it can be linked at launch time.
Have you tried using the release XCFramework across your configurations? Unless they are encoding environment configuration such as different endpoints in their frameworks (which is not a good idea and I’d push them to change that), it should be fine to use a release XCFramework for an arbitrary configuration of yours.
I can’t really go into too many details — this vendor is very tight-lipped — but I can say that due to some security tools being used, we have to use the specific XCFramework that’s built for each configuration. (At least with the current way they’re building the frameworks.)
I’m almost certain things could be made better, but the vendor just isn’t interested in putting in the time to make it better. It’s very frustrating.