mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-27 02:01:35 -04:00
2.1 KiB
2.1 KiB
Decision: Hilt → Koin Migration
Date: 2026-02-20 to 2026-03-09 | Status: Complete
Context
Hilt (Dagger) was the strongest remaining barrier to KMP adoption — it requires Android-specific annotation processing and can't run in commonMain.
Decision
Migrated to Koin 4.2.0-RC1 with the K2 Compiler Plugin (io.insert-koin.compiler.plugin) and later upgraded to 0.4.0.
Key choices:
@KoinViewModelreplaces@HiltViewModel;koinViewModel()replaceshiltViewModel()@Module+@ComponentScanincommonMainmodules (valid 2026 KMP pattern)@KoinWorkerreplaces@HiltWorkerfor WorkManager@InjectedParamreplaces@Assistedfor factory patterns- Root graph assembly centralized in
AppKoinModule; shared modules expose annotated definitions - Koin 0.4.0 A1 Compile Safety Disabled: Meshtastic heavily utilizes dependency inversion across KMP modules (e.g., interfaces defined in
core:repositoryare implemented incore:data). Koin 0.4.0's per-module A1 validation strictly enforces that all dependencies must be explicitly provided or included locally, breaking this clean architecture. We have globally disabled A1compileSafetyinKoinConventionPluginto properly rely on Koin's A3 full-graph validation at the composition root (startKoin).
Gotchas Discovered
- K2 Compiler Plugin signature collision: Multiple
@Singleproviders with identical JVM signatures in the same@ModulecauseClassCastException. Fix: split into separate@Moduleclasses. - Circular dependencies:
Lazy<T>injection can stillStackOverflowErrorifLazyis accessed too early (e.g., ininitcoroutine). Fix: pass dependencies as function parameters instead. - Robolectric
KoinApplicationAlreadyStartedException: CallstopKoin()inonTerminate.
Consequences
- Hilt completely removed
- All 23 KMP modules can contain Koin-annotated definitions
- Desktop bootstraps its own
DesktopKoinModulewith stubs + real implementations - 11 passthrough Android ViewModel wrappers eliminated
Archive
Full migration plan: archive/koin-migration-plan.md