A minimalist Kotlin Multiplatform (KMP) demo showcasing how to use Koin Annotations for dependency injection in a Compose Multiplatform project.
⚙️ Part of the KMP Bits series — hands-on examples for real-world KMP development.
- Koin Annotations: Use
@Single
,@Factory
, and@KoinViewModel
for concise and type-safe dependency declarations. - Compose Multiplatform UI: Shared UI code across Android and iOS platforms.
- Platform-specific Implementations: Use
expect/actual
for platform-specific logic, such as logging. - Gradle & KSP Configuration: Set up KSP for code generation and include generated sources in your build.
- ViewModel Integration: Manage state with
StateFlow
and handle asynchronous operations usingviewModelScope
.
- Android Studio: Giraffe or newer.
- Kotlin: 1.9 or newer.
- KSP Plugin: Ensure KSP is applied and configured correctly.
-
Clone the repository:
git clone https://github.com/kmpbits/KoinInjectDemo.git cd KoinInjectDemo
-
Open in Android Studio
Open the project in Android Studio and let it sync. -
Run on Android
Select theandroidApp
configuration and click Run. -
Run on iOS
Open theiosApp
module in Xcode, choose a simulator or device, and click Run.
KoinInjectDemo/
├── androidApp/ # Android-specific code
├── iosApp/ # iOS-specific code
├── composeApp/ # Shared KMP logic and Compose UI
├── build.gradle.kts # Root build file
├── settings.gradle.kts # Gradle project settings
└── README.md
- Using
@ComponentScan
and manually declared modules - ViewModels in shared code with
@KoinViewModel
- Gradle configuration for KSP and metadata generation
- Platform logging with
expect/actual
- Dependency testing using fake implementations