https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
t

Tarika Chawla

09/27/2021, 2:43 PM
Hi all, Anyone has any experience integrating a KMM in a Development Pod in iOS instead of the project itself? I was able to import the KMM in the development pod by adding it through podspec file but hitting a roadblock when I call those functions.
l

louiscad

09/27/2021, 5:07 PM
Hi, what is the roadblock you're hitting?
t

Tarika Chawla

09/27/2021, 5:16 PM
I have an app which uses that Development pod. When I run the app which further calls the function in the development pod (which has the KMM function), the app just crashes.
Right now, I am adding the KMM to the library like this: 1. Project file: Add the path the podspec file generated by KMM gradle 2. run pod install 3. It added the KMM module as a cocoapod int he development pod folder 4. Then I referred to that development pod in the podspec file of my ios library (development pod) this way:
Copy code
s.dependency 'accesstokenmodule'
l

louiscad

09/27/2021, 5:30 PM
What's the crash cause exactly?
The logs should show why the crash happens.
t

Tarika Chawla

09/27/2021, 5:32 PM
There is no error. It just goes to memory management with this
Kotlin_ObjCExport_toKotlinSelector
This is consistent with any function I tried calling which is in that Kotlin module.
There are no logs at all. thats why its so hard to track down a solution I guess.
l

louiscad

09/27/2021, 5:35 PM
I'd try to get another pod to work, starting from the Cocoapods Kotlin doc, or from an official sample, and once I get it working, I'd look at how the setup is different with what crashes
t

Tarika Chawla

09/27/2021, 5:36 PM
Just one thing though. When I try to call a function in the app instead of a development pod from this same KMM. the app works and there is no crash
My first assumtpion was maybe KMM only supports integration with an ios app and not in the development Pod?
l

louiscad

09/27/2021, 5:37 PM
The first call to Kotlin code from the pod crashes, did I understand correctly?
t

Tarika Chawla

09/27/2021, 5:37 PM
yup, from the pod it crashes! But same thing from the app, it doesnt crash?
l

louiscad

09/27/2021, 5:37 PM
It's very possible it's not supported. I'd ask @akapanina to be sure.
t

Tarika Chawla

09/27/2021, 5:39 PM
hmm okay. Thank you so much for looking into it and guiding me ahead 🙂 I really appreciate it.
Just an update, We were able to resolve the issue. It looks like the integration with the development pod is possible. The only thing to take care of is that the KMM is available by the time we try to instantiate it. As an example, if my KMM has a
class Foo
with a function
getFooString()
. I need to make sure that by the time I instantiate the Foo class as `private let foo = Foo()`the KMM module should be loaded. More like a race condition. In order to solve it, we added
private lazy var
instead of using
private let
when instantiating the class the very first time. So we wait till we need to use it in the hope that it will be available by then.
🔥 2
l

louiscad

09/29/2021, 6:21 PM
Great that you found the solution! What do you call the "KMM" exactly?
t

Tarika Chawla

09/29/2021, 10:12 PM
Kotlin Multiplatform Module
l

louiscad

09/29/2021, 10:34 PM
FYI, KMM stands for Kotlin Multiplatform Mobile, hence my request for clarification 🙂
t

Tarika Chawla

09/29/2021, 11:13 PM
ahh okay! Thank you 🙂
3 Views