I'm working with Kotlin Multiplatform and I want t...
# multiplatform
v
I'm working with Kotlin Multiplatform and I want to set up the following scenario: Create a Kotlin Native library named 'CommonLibrary' that defines a common interface. Develop an iOS Swift framework named 'iOSFramework' that implements the interface from 'CommonLibrary'. Build an Android module named 'AndroidModule' that implements the same interface from 'CommonLibrary'. Create a separate Kotlin Multiplatform project: In the 'commonMain' source set, use 'CommonLibrary' to define an expected factory function that returns the common interface. In the 'iosMain' source set, use 'iOSFramework' to provide the Swift implementation for the common interface. In the 'androidMain' source set, use 'AndroidModule' to provide the Kotlin implementation for the common interface. My goal is to share the common interface and logic across platforms while using platform-specific implementations where necessary. Is this setup achievable?"
I tried doing that but encountered a problem. I've built my CommonMain library into xcframework. My iOSFramework links with CommonMain.xcframework But that results in the following: CommonMain defines interface IDevice, in iOSFramework that name is mangled into NEKIDevice. Than mt separate kotlin multiplatform project actual fun implementation complaints that: Inferred type is NEKIDevice, expected IDevice. It's like there are now two different versions of IDevice one from direct link to CommonMain and other via iOSFramework
a
just in case, you don't need to split the common from specific code into separate projects. you can place the specific platform code and common on the same module, android won't get the ios code and viceversa, look at each sourceset as a module, they all get compiled into a library for each platform in the end, but the coding process is separate on each sourceset