Hey, I am working on multi module application for ...
# multiplatform
j
Hey, I am working on multi module application for iOS and android. My project include 4 modules: 2 KMM (messenger, mainModule) and 2 native ones (biometry, faceCheck). Messenger is used across all other modules in project. When I am trying to consume Messenger’s common code (KMM module) in different KMM module I have to add .aar/.xcframework file to native parts, create service for each architecture and use it, but doing it this way I need to duplicate common code for each architecture. Is there any other way of using common code of KMM module in different KMM module? Is it possible to use common code of KMM module in common code of different KMM module?
v
Is it possible to use common code of KMM module in common code of different KMM module?
Yes, it should totally work. Are you connecting dependency like so?
Copy code
// build.gradle.kts

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                implementation(project(":messenger"))
            }
        }
    }
}
t
In your KMM module are you specifying all supported platforms in gradle? Kotlin doesn't support just a generic "kotlin" library. You need to add each target in gradle you want to support even if you only are writing code in commonMain
j
Yes, i am specifying all supported platforms. First photo contains my project structure (supported architectures), on second one you can see mainModule source set configuration. I am adding messenger to every architecture using "project" tag. Doing so I can see and use contents of Messenger on every architecture without any errors but when I generate final binaries for both modules - .xcframework and try to test it on swift app, it is not working. I mean I am adding messengerModule, mainModule as dependencies to swift testApp, next I am registering callback in test app to receive messages using messengerModule. Next I am starting process using mainModule, which should send message using messengerModule and I am not receiving it in test app callback, even though it's the same reference of messengerModule. I really don't understand why. On third photo you can see other way of using messengerModule in mainModule, I am adding messengerModule as dependency using C-Interop. Doing so I can see and use contents of messenger just in native architectures, I cannot use it from commonMain what results with multiplying code. But when I am testing it from swift app, and doing same process as described above I am receiving messages in testApp callback sent from mainModule using messengerModule. Can someone explain why I am not receiving messages in swift testApp callback from messenger used in mainModule by "project" tag even though it is the same reference? Am I doing something wrong?