I’ve struggled for a quite some time embedding the composeApp module into the iOS build when building from XCode. I’ve managed to get it working on a simulator for no apparent reason – either restart of something or I started a gradle which linked the two.
My problem is, XCode still fails whenever I try to build the app on my Mac, giving me No such module ComposeApp
. And while it works on simulator devices, the code updates don’t seem to take effect, as the app is crashing on No definition found for type 'ui.login.UserOperationService'. Check your Modules configuration and add missing type and/or qualifier!
but I’ve renamed that class to UserOperationServiceTEST
like an hour ago just to test if it updates – and it doesn’t.
So I suppose there is a problem with the ComposeApp module being embedded within iosApp module either way.
This is my Compile Kotlin framework
script: if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to "YES"" exit 0 fi cd "$SRCROOT/.." ./gradlew :composeApp:embedAndSignAppleFrameworkForXcode
Based on the documentation, this should be sufficient, yet, it clearly isn’t.
Am I missing something? Is there a gradle script I can run in Android Studio, which would link the two manually?
2
Answers
After three painful days, I figured out what was wrong with my configuration. For anyone struggling the same way, it was very useful for me to create a blank project via the Kotlin Multiplatform Wizard, try to run it, then, compare the differences between my project and the blank project that run correctly.
The very answer to my problem was within
build.gradle
- thus, not anything within the iosApp folder itself. I incorrectly set thebaseName
property withiniosTarget.binaries.framework {
to my package name during the development. However, after setting itbaseName = ComposeApp
the project actually started working on every device. Both simulators, and macOS.The problem is related in the build.gradle file, You should have something like listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { iosTarget -> iosTarget.binaries.framework { baseName = "ComposeApp" isStatic = true } }, this should solve the problem