Kotlin multi-platform boilerplate including mobile
There is a mobile only version in this repo
Read my blog if you want more details:
This is an example of using Kotlin native to share the code between iOS and Android. It contains the tests for all the platform code. Setup via the support from multiplatform kotlin.
This setup is aiming to solve the problem, where we want to write the platform specific code in a
- android: Android project built by Android Studio
- ios: iOS Project built by XCode
- jvmApp: jvm app which consumes the lib
- jsApp: js app on how to consume the lib
- common: The shared code that is meant to be across all platforms without any change.
- platforms: platform specific implementation which will be compiled with
- ios: it will be compiled as an iOS framework
- jvm: a dependency for both
- Work on Android App: Open
Androidfolder in Android Studio
- Work on iOS App: Open
iOSfolder in XCode
- Work on sharing code: Open the root folder in
IDEAor any other IDE.
In fact, you can edit the sharing code in android studio as well, as we embed them as module, and they all use the same language.
About the example
Sampleclass is for code that is sharing across platforms (Which means you only use API from
kotlin-stdlib-commonor some other cross platform lib).
Platformclass is a class which has been implemented twice for different platforms for showing the platform API case.
Androidfolder in Android Studio, run the app, it will show a string from the
iOSfolder in XCode, run the app, it will show a string from the
And the string is from both platforms are retrieved from the
If you think the XCode building phase is slow. That is because it will build the KN generated iOS framework every time. You can modify it by just copying the framework files without building it. Because you can always edit Kotlin native code somewhere else.