Why it occurs
Once you create a KMP undertaking with Compose Multiplatform, the shared code (together with the Compose UI) is compiled into an iOS framework (often referred to as shared.framework
or one thing related) that must be imported into your Xcode undertaking.
If the Xcode undertaking isn’t pointing to the fitting output folder or hasn’t constructed the framework but, Swift will say:
No such module 'ComposeApp'
Steps to repair it
-
Make sure the iOS framework is constructed
-
In Android Studio (or by way of terminal), run:
./gradlew :shared:packForXcode
or in case your module is known as in another way:
./gradlew :composeApp:syncFramework
This activity generates the
.framework
file inshared/construct/XCFrameworks
.
-
-
Test your Xcode undertaking setup
-
In your iOS app’s Xcode undertaking, go to Frameworks, Libraries, and Embedded Content material and ensure the generated
ComposeApp.xcframework
(or no matter it’s named) is added. -
If it’s lacking, drag it from the Gradle construct output folder into Xcode.
-
-
Replace the import path
-
In your Swift code, import it precisely because the framework is known as — if the framework is
shared
, you’ll use:import shared
In case your KMP undertaking named it
ComposeApp
, then:import ComposeApp
-
-
Re-sync Gradle and Xcode
-
Typically adjustments don’t mirror till you clear and rebuild:
./gradlew clear ./gradlew :shared:packForXcode
Then in Xcode: Product → Clear Construct Folder and rebuild.
-
-
Match the iOS goal
-
Be certain that the Gradle construct is creating the framework for a similar structure your simulator or machine makes use of (
arm64
for gadgets,x86_64
for Intel simulators,arm64
for Apple Silicon simulators). -
For those who run into structure mismatches, you may specify:
./gradlew :shared:packForXcode -Pkotlin.native.cocoapods.goal=iosSimulatorArm64
-