
Under the com.example package, create a Manager interface. Don’t worry if the code does not compile for now. Copy the source code below into Store.kt. Store will depend on two other classes that we will tell Dagger to inject them at runtime. Under the package com.example, create a data class called Store. To be able to use DI, we are going to need an object that depends on some other objects. This is where your main function lives, so create a main() function here. Ĭreate a new file Entry.kt under the package com.example. Later on, we will put Dagger boilerplate code in them. Under the kotlin directory, create the packages below.

This will bring in necessary libraries and annotation processing for your project. In your IDE, go to Build -> Build Project. Wait a few seconds for the project to build.Ĭopy and paste this exact same gradle configuration below into your file. Leave the next screen as default and click Finish. This is how the project setting looks like:

I find this version to be most stable when working with Kotlin. You can leave the Location as default if you wish.į. Use Dagger2Practice as project name(optional).Ĭ.

The most obvious benefits of using Hilt are reduced boilerplate code and lifecycle-aware components( and their associated annotations). In Android development, the current recommended library for Dependency Injection is Hilt.
