Hi all, Is there a way to create a KMM module inde...
# multiplatform
t
Hi all, Is there a way to create a KMM module independent of the app/ project?
m
You can create a folder with a
build.gradle[.kts]
file and apply the multiplatform plugin
What do you want to put in your module?
t
Just the code needed in the KMM module like build.gradle, src/commonnMain, iOSMain, androidMain
The issue is that when I create a module in the project, it auto generates the podspec file which links to the app's gradlew. I want to have an independent module.
Does that mean I need to create a KMM Library? @mbonnin
m
Not super familiar with the podspec stuff. What is the problem if it links to the app's gradlew ?
Are you trying to avoid adding a Gradle build step in XCode?
t
I want to use this kotlin module as a dependency in other apps so I want to make it part of the library and not the app. But the library itself is a react-native library
So, react-native library can have native modules. In my case, I am trying to add this KMM module as a dependency to that native module.
But I cant figure out how to create it independent of my demo app which has a gradlew
m
So using KMM from react native ?
t
not directly, but through a native module which further depends on that KMM
m
KMM itself is relatively dependant on Gradle for building libs.
You could build a .jar for Android and a .framework for iOS and then use that from React Native
t
So, I guess the project needs to have a gradlew to add a KMM
Unless I create a standalone library and then create a KMM module in it
m
Yea, to build the .jar or .framework you mostly need gradlew
t
make sense! Thank you 🙂
s
Putting a Kotlin Native object into iOS’s JavaScriptCore is going to be problematic. You'll need to freeze the objects before adding them to the JavaScript Context because the vm runs on a background thread and so does the garbage collector.
t
In my case, javascript code calls a native iOS module which will then call the Kotlin function. In that case, I am assuming its fine?
s
If the Swift/ObjC code is creating the Kotlin object, you’ll be fine.
👍 1