I am trying to set up an ios / swift project in a ...
# multiplatform
m
I am trying to set up an ios / swift project in a way that for debug build uses
embedAndSignAppleFrameworkForXcode
and for release
assembleSharedReleaseXCFramework
. The building part is easy, I just conditionally run one gradle task or the other. Things get messy when the framework needs to be embedded. I can't use the Embed Frameworks build phase to embed shared.xcframework, because it will also require the xcframework for debug builds. There is no conditonal setting there. And I tried to embed it manually via xcconfig or another script the copies and signs the framework, but I always end up with "No such module 'shared'" in xcode. Do you have a similar setup? Or maybe I am trying to do something completely useless? My idea was that for debug builds I want the faster method but for release I need xcframework.
f
start a new KMP project from the android studio assistant and use default config, It’s a good comparison
m
The default project uses embedAndSign which works perfectly. It's the xcframework that i have a problem with when I don't use embed frameworks build phase
f
You need to master xcode 😄
Well, by default xcode has 2 config release/debug, in the tab Build settings of your target, you can customize each row by config
m
Yeah, but I cannot differentiate the Build Phase Embed Frameworks. Unless I am missing something
f
you need to update the line FRAMEWORK_SEARCH_PATHS
set the path for the release and the debug one (relatively)
then, you can change the OTHER_LDFLAGS to ->
-framework NameOfYouFramework
m
Tried that. Debug.xcconfig
Copy code
FRAMEWORK_SEARCH_PATHS = $(inherited) $(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)
OTHER_LDFLAGS = -framework shared
Release.xcconfig
Copy code
FRAMEWORK_SEARCH_PATHS = $(inherited) $(SRCROOT)/../shared/build/XCFrameworks/release
OTHER_LDFLAGS = -framework shared
(and of course i reference those xcconfigs properly, they are used in the build process, i checked that)
the debug one works fine, the release doesn't 😞 although the path is fine, I double checked that the framework gets generated there. I also tried to copy it to the build directory and add a search path there
f
check your build warning, it will tell if there is something wrong with the paths
m
The only warning I have seems irrelevant
Copy code
Run script build phase 'Build the framework' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase.
and then it's just the error
Copy code
/Users/.../iosApp/iosApp/iOSApp.swift:2:8: No such module 'shared'
f
the first is (not) normal, we can’t fix it.
👍 1
It is difficult to find a solution at your issue, everybody cook their project at their taste (pardon my French 😄) You can have a messy Xcode project like you have a messy Gradle config.
m
It's a pretty basic project, not much there yet. I guess I could recreate it from scratch using the android studio template. At the end of the day using Embed Frameworks Phase fixes it, so I doubt it's any issue with the xcframework itself. Probably embedding the framework "manually" requires one more extra step and I was wondering if anyone has done something similar
f
This kind of manipulation is not simple when we are not familiar how works framework with Xcode
p
I tried that but I wasn't able to achieve a successful result. I ended up with 2 branches, one with the
framework
integration the other with the
xcframework
integration and using SPM. The down side is that I had to keep rebasing all the time.
sad panda 1
I ended up doing the framework integration directly in Xcode.
m
I just tried with a completely fresh project directly from android studio and it looks exactly the same. There is something that needs to be done additionally to embed the xcframework properly. Wonder what
embedAndSignAppleFrameworkForXcode
does under the hood, maybe it's worth checking out (leaving it here mostly for myself to find it later https://github.com/JetBrains/kotlin/blob/dcb77235383a76e8915fe6cba5b093287ab8de5e/[…]org/jetbrains/kotlin/gradle/plugin/mpp/apple/AppleXcodeTasks.kt)
> Or maybe I am trying to do something completely useless I feel like answer to that questions might have been yes. For some reason I thought that for production builds I will need an xcframework anyway, but that doesn't seem to be true after reading the source code of the
embedAndSign..
. task. It generates more than one architecture for production build in a form of a fat framework. Although maybe the fat framework is not an ideal choice in the long run...