Dependency Injection with Koin in Android KMM app

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Dependency Injection with Koin in Android KMM app
Simple
~2-3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Dependency Injection (Koin) in Android/KMM App

Koin—DI framework on Kotlin DSL without code generation. Suitable where Dagger/Hilt is overkill: small-to-medium apps, KMM projects needing shared DI for Android and iOS, teams that don't need kapt or KSP in build.

Basic Setup

// build.gradle.kts
implementation("io.insert-koin:koin-android:3.5.0")
implementation("io.insert-koin:koin-androidx-viewmodel:3.5.0")

Dependency module:

val appModule = module {
    single<UserRepository> { UserRepositoryImpl(get()) }
    single { ApiService(get()) }
    factory { AuthUseCase(get()) }
    viewModel { LoginViewModel(get()) }
}

single—singleton for lifetime of Koin container. factory—new instance on each request. viewModel—creates ViewModel and registers in ViewModelStore.

Initialization in Application:

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        startKoin {
            androidContext(this@App)
            modules(appModule)
        }
    }
}

In Fragment or Activity:

val viewModel: LoginViewModel by viewModel()
val repository: UserRepository by inject()

Koin in KMM

In Kotlin Multiplatform, Koin allows you to declare shared dependencies in commonMain and platform-specific ones in androidMain / iosMain:

// commonMain
val commonModule = module {
    single { UserSyncService(get()) }
    factory { SyncUseCase(get()) }
}

// androidMain
val androidModule = module {
    single<DatabaseDriver> { AndroidSqliteDriver(Database.Schema, androidContext(), "app.db") }
}

// iosMain
val iosModule = module {
    single<DatabaseDriver> { NativeSqliteDriver(Database.Schema, "app.db") }
}

On iOS Koin is initialized via KoinApplication:

// Swift
KoinKt.doInitKoin(appDeclaration: { _ in })

This is the key advantage over Hilt: Hilt is Android-only, Koin works in shared code.

Typical Mistake

NoBeanDefFoundException at runtime—Koin didn't find binding for requested type. Reason: forgot to add module in startKoin, or type in inject<T>() doesn't match registered one (interface vs implementation). Unlike Dagger, error surfaces not at compile time but at first dependency access. For early detection—checkModules() in tests:

@Test
fun verifyKoinApp() {
    koinApplication {
        modules(appModule)
    }.checkModules()
}

Setting up Koin for Android project—0.5–1 day. For KMM with multiple platform modules—2–3 days. Cost is calculated individually.