DEV Community

Cover image for No such module 'Shared' fixed for KMP Xcode
Saad Alkentar
Saad Alkentar

Posted on

No such module 'Shared' fixed for KMP Xcode

I believe you have already tried to open Kotlin multi-platform iOS project in Xcode, and voalla, No such module 'Shared'

Let's jump directly to the solution. You can also find the solution here

  • Start by choosing to edit schemas in Xcode

Edit build schema

  • Then add the script as a pre-build action

Add prebuild script

cd "$SRCROOT/.."
./gradlew :shared:embedAndSignAppleFrameworkForXcode
Enter fullscreen mode Exit fullscreen mode

and make sure to select to provide the build settings from iosApp

select build settings

  • Time to try to build again, success? Good for you, same error? move on ...

  • Let's debug the script to find the issue

echo "Hello world"
cd "$SRCROOT/.."
./gradlew :shared:embedAndSignAppleFrameworkForXcode
Enter fullscreen mode Exit fullscreen mode

build script issue

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Enter fullscreen mode Exit fullscreen mode

So, couldn't find the Java runtime...

I need to set JAVA_HOME. We can do it on the system level, the script level, or on the project level. I'll choose the third.
Select your project, project properties, click the add button, and add a user-defined setting.

Add user defined settings

and add the JAVA_HOME env var

Set java_home

For my device, the path is

export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"
Enter fullscreen mode Exit fullscreen mode

It should build successfully now

Stay tuned for Networking with KMP

Successful bulid

Top comments (0)