This Kotlin Multiplatform project targets Android and iOS using Compose Multiplatform.
💻 Techstack
- Kotlin Multiplatform
- Compose Multiplatform for sharing UIs across multiple platforms with Kotlin
- Swift UI (Optional)
- 🗡️ koin for Dependency Injection
- ☁️ ktor for networking
- 🔗 Kotlin Serialization as primary JSON (de)serialization tool
- 🔄 Kotlin Coroutines for async operations
- 📦 Room (Kotlin Multiplatform) for persistent SQL storage
- 🗂 DataStore (Kotlin Multiplatform) for persistent NoSQL storage
- 📱 Shared ViewModel by AndroidX
- 🧭 Voyager for navigation
- 📲 SKIE - Swift Kotlin Interface Enhancer by Touchlab
- 🖼 Coil for loading images
- ✨ Spotless for code-format control
- 🔍 Detekt for static code analysis
📒 Todo
- Jetpack Navigation
- Deeplink Support
- Build Logic
- Open the project in Android Studio.
- Wait for the build to finish.
- Select
composeApp
from theRun/Debug
Configurations. - Apply and run.
- Navigate to the
KMP-Template/iosApp
directory. - For first-time setup:
- Open terminal in that directory and run the command
pod install
. - It’ll generate the
iosApp.xcworkspace
file.
- Open terminal in that directory and run the command
- Open the
iosApp.xcworkspace
file in Xcode. - Choose the correct target for your device or simulator in the scheme chooser at the top of the window.
- Build and run.
If you want to run the iOS app with swift UI (not compose multiplatform)
- Open the
iosApp.xcworkspace
file in Xcode. - Navigate to the
iosApp/presentation/ContentView
file in Xcode. - Inside the ContentView body, uncomment the line
SplashScreen()
and comment out theComposeView().ignoresSafeArea(.keyboard)
. - Build and run.
-
/composeApp
: Contains code shared across the Compose Multiplatform applications.commonMain
: Holds code that's common for all targets.- Platform-specific directories (e.g.,
androidMain
,iosMain
): Contain Kotlin code that will compile only for the designated platform. For iOS-specific Kotlin code, such as integration with Apple's CoreCrypto, usesiosMain
.
-
/iosApp
: Contains the iOS application. This is the necessary entry point for the iOS app, even when sharing UI with Compose Multiplatform. This is also where to add any SwiftUI code for your project.
Template implements Clean Architecture and follows best practices provided by Google with some tweaks here and there
The Presentation layer or UI Layer is our Jetpack Compose UI screens and components, and ViewModels. The Presentation layer interacts with the Domain Layer where our business logic resides.
The domain layer contains the application's business logic. This layer only works with abstractions and as such it never knows about how different layers look like. It doesn't know about any Databases, APIs, or even any Frameworks.
The data layer is where the actual interactions happen between different data sources. This layer “implements” parts of the Domain layer and communicates with the APIs, Databases, and other services and SDKs.
These are the tools used in the template, to improve the development, that you should be aware of:
Spotless is a Gradle plugin used for consistent code formatting and style conventions across the project. You can use it running the following Gradle commands:
./gradlew spotlessCheck
- Checks the style formatting and displays any issues
./gradlew spotlessApply
- Same as above but automatically tries to fix most of the issues. If for any reason it can't, then a list of problems is displayed.
For more information on Kotlin Multiplatform, visit the official documentation.