https://kotlinlang.org logo
Title
v

Vivek Mittal

05/05/2023, 10:13 AM
I created a multiplatform library. Integration with iOS went smoother than expected. On Android, seeing a bunch of exceptions one after another. Added a few dependencies that were added to the multiplatform lib. Do I really have to add indirect dependencies? Most importantly, I am getting an exception.
Engine doesn't support WebsocketCapability.
Can I not use sockets in the multiplatform library? IMO it should support.
n

Norbi

05/05/2023, 11:56 AM
You can, just choose an engine which supports websockets. https://ktor.io/docs/http-client-engines.html#limitations
Do I really have to add indirect dependencies?
What do you mean? In a library you should not add concrete engine dependencies but use the core ktor libraries instead (ktor-server-core, ktor-client-core, etc). The users of your library will choose a preferred engine (of course with some limitations like if your library uses websockets then the chosen engine should support it of course).
v

Vivek Mittal

05/05/2023, 2:06 PM
This was super helpful. Thanks.
About the dependencies - App A uses a kmm library B, which uses C & D libraries (gradle dependencies). When A integrates B, it also needs to add C & D in the gradle dependencies. Correct? In c# or cocoapods world, B needs C & D, but it automatically brings them.
n

Norbi

05/05/2023, 2:52 PM
When A integrates B, it also needs to add C & D in the gradle dependencies. Correct?
Only if B declares C & D as
imlementation()
dependencies. If B declares C & D as
api()
dependencies then C & D will be automatically available in A as well:
// build.gradle.kts of B

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                api("C")
                api("D")
            }
        }
    }
}