Using kmp, do we have a way to provide our own act...
# multiplatform
p
Using kmp, do we have a way to provide our own actual implementation when a Kmp library doesn't support a target that we do? I'm thinking about playing with gradle resolution to point to a local version, but I have a feeling that may not work 🫣 Anyone tried something like this? 🙏
m
Yes you can do that. You can create a custom group for the supported targets by the library in your build.gradle.kts:
Copy code
kotlin {
    applyDefaultHierarchyTemplate {
        common {
            group("mobile") {
                withAndroidTarget()
                withIos()
            }
        }
    }
}
And then you can import the library only for that group and use expect actual, the actual in mobile will use the library implementation and the actual in the non supported target will use your implementation for that specific target.
Also you can even keep the implementation empty for that target if you don't need it or it's hard to implement the feature there and you will be able to run the code from common and it will work for the supported targets and will be ignored for other targets.
p
Oh, I wasn't aware of groups, I'm gonna give that a try, thank you 🙏 The think it's not clear is how would the compiler match the expected to the actual on the local implementation. I'm hopeful that matching api would be sufficient. I'll play around with this though 🙂
m
What are you trying to do exactly?
p
I'm trying the new Kmp view model lib from Google, but they didn't include web as one of the targets. It's a beta, so I'm hopeful they'll add the target, but in the meantime I wanted to try to provide a web version. Worse case I may wrap the whole of the lifecycle in a local lib and consume it from there.