Android Dependency Injection: Migrating from Hilt to Koin

Iván Garza Bermea
Level Up Coding
Published in
9 min readJul 12, 2024

--

Source: https://www.techyourchance.com/dependency-injection-in-modularized-android-applications/

Recently, I decided to switch Dependency Injection (DI) tools in my Android project. The idea is to migrate from Dagger’s Hilt, and into the more compact Koin library. The reason I’ve decided to do this change is to use a library that betters supports the continuous effort to convert this personal project into a KMM application. Koin is a much better library for this, as it supports KMM right-off-the-bat, and I don’t have to worry about finding an alternative solution for iOS.

I have written a light-weight comparison between the Hilt & Koin libraries before, but this time we’ll showcase how to migrate from one to the other. In theory, this guide should be mostly applicable to do the opposite migration as well, but I cannot assure any guarantees on that last claim!

We’ll start from the beginning, by bringing in the Koin dependencies. We’ll then go over the migration guide step-by-step, and we’ll close out this piece by removing all the left-over Hilt code, as well as its dependency declarations.

Getting Started

Anyhow, let’s get started with our present inquiry. The first step is to bring in the Koin library into your project. With modern Android projects, there are two main ways of doing this: the traditional way of simply introducing dependencies inside the…

--

--

Android Engineer @mixhalo | Graduate Student of Philosophy @SFSU | Passionate fútbol fan | Amateur salsa maker