Hi, I am researching KMP as an option to implement...
# library-development
d
Hi, I am researching KMP as an option to implement shared business logic code within our existing android and iOS sdk. Is my understanding of using KMP for shared code accurate?..... 🧵
As a first step I just want to take a simple KMP project (like GreetingKMP) and turn that into a library project to be consumed locally by my native android and ios sdks. I was hoping that I don't have to change much in my existing sdk apart from: • android: update the gradle file to depend on a local gradle project(or aar) • ios: update my podspec to add the GreetingKMP pod
I couldn't find an appropriate basics setup in the samples page makes me think my approach might be off? Perhaps I need to turn my existing sdks into KMP first?
Is there any existing sample or open source that I could learn from? Any advice or tips? Thanks!
c
> • android: update the gradle file to depend on a local gradle project(or aar) Yes. On Android, KMP is handled by Gradle, just like everything else. So you would create a new
build.gradle.kts
with the
kotlin("multiplatform")
plugin, include it in your main
settings.gradle.kts
, then you can depend on it with
project("your-kmp-library")
just like you depend on any other library modules. > • ios: update my podspec to add the GreetingKMP pod I don't do iOS development myself, so I can't tell you how easy it is to do, but there is an official tutorial to do exactly what you asked: https://kotlinlang.org/docs/apple-framework.html
@John O'Reilly has many great sample apps with KMP: https://github.com/joreilly
d
Oh great, thanks for the info and steer. As a quick hack I saw that the sample Greeting project generated an aar file which I included in my native android project like this:
Copy code
api fileTree(dir: '<your_path>/KotlinProject/shared/build/outputs/aar', include: ['shared-debug.aar'])
Obviously not a good idea and I'll try getting the setup you mentioned. But first, will try to get xcode using the generated framework...
I was able to include the generated framework in my app by copying the "Compile Kotlin Framework" build phase of the iosApp xcode project from the sample Greeting project.
Copy code
./gradlew :shared:embedAndSignAppleFrameworkForXcode
Again a hack, but neat to quickly see shared code running in my app!! Now for more docs reading!
c
Yeah, that's basically how it works! The official setup will make the IDEs aware of this though, so you can just press ‘build’ and whatever needs to happen happens
❤️ 1