I am trying to share a viewmodel with KMM-Viewmode...
# multiplatform
a
I am trying to share a viewmodel with KMM-Viewmodel lib
r
Please make sure that
KMMViewModelCore
is listed under "Frameworks, libraries and embedded content" option of your target. https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app
🙌 1
a
Was not expecting to get a response from the creator himself 🤣, Thank you for your work i will look into it
👍 1
🧵 1
Alright I am where i started again, whenever i try and add the package dependency here the framework is not getting added and i do not understand xcode well enough
The docs do not mention this part here and I am guessing there is something wrong in the android gradle config?
r
This specific error is unrelated to the Kotlin setup. It seems your Xcode project is missing the frameworks setting. Could you try the following: https://github.com/JetBrains/compose-multiplatform/issues/4026#issuecomment-1895372428
a
That worked perfectly, thanks a lot man
also thank you for your hard work and support 🙂
👍 1
j
May I ask @Rick Clephas as you sound like having good knowledge about this. Is it expected always need to add deps into Xcode. Like consume KMM viewmodel or any library using cocoapods or such. Do I then always manually need add deps they use? Or can I do dynamic linking with transitive deps somehow?
r
You can use transitive dependencies through a dependency manager like CocoaPods or SPM (which is just an easy way to get those dependencies into Xcode). I believe that’s exactly what the cocoapods plugin for KMP does (haven’t really used that though). The reason why KMM-ViewModel has separate dependencies for Swift is simply because that allows the Swift logic to be decoupled from your shared Kotlin code (which is required to turn it into a library). So when using the cocoapods plugin I guess you could also add the dependencies there instead of in Xcode directly. I don’t believe there is a way for Kotlin dependencies to specify their cocoapods/spm dependencies directly though.
j
Yeah problem in my case is if library using cocoapods its not exported into my module consuming them. Need to add those manually anyway. Maybe I am missing something. But also if using Swift libs. This is my major pain point with iOS at moment. Obstruct from regular Gradle dependency handling and which libraries can use. I would expect the library to just work and get Gradle transitive deps passed through spm/ cocoapods. If I depend on KMM viewmodel in this case I dont expect anything being added to Xcode ever. And no lining flags. There is no way export or pass linking instruction to Xcode resolve this somehow? I know Jetbrains working on better Swift interop and I guess that also infer better solution to this. Like directly able to use CryptoKit or any Swift library.
Example case: https://github.com/GitLiveApp/firebase-kotlin-sdk/blob/master/firebase-firestore%2Fbuild.gradle.kts I dont follow why those cocoapods not resolved in my project consuming it in iOS.
r
Yeah no it isn’t possible for gradle dependency to do that. The thing is you don’t need to use cocoapods so there wouldn’t be a way for such a gradle dependency to know how to get the correct native dependency. Regarding the cocoapods dependencies you might need to export those through `transitiveExport`: https://kotlinlang.org/docs/native-cocoapods-dsl-reference.html#framework-block.
j
Isnt Gradle able using like Kotlin metadata or such? To read dependencies from library used and resolve transitive deps. Given build process tells if maven, cocoapods, spm, npm or such. Just trying understand if need to live with this forever or actually possible solve.
r
Yeah I guess it would be doable, but like I said as far as I know this isn’t something that is currently supported.
j
Yeah the transitiveExport + export requires dynamic I think, but then other libs not working require static 😁 Also Imagine having module A, B, C, shared. Where shared -> C -> B -> A and shared used by iOS. Then I think each module need export theoretical all libs iOS target potentially using. Thats where I would expect Gradle resolve this as they always do for other targets like jvm, Android and such. Also this maybe similar in wasm and js resolve npm libs, not sure. Feels to me like major blocker get KMP being usable for both library owners and consumers. I hope its solveable and Jetbrains has a plan for it.