Mastering Hilt - Android | Kotlin | Hilt (Dagger 2) [ Part 1]
Becoming Proficient in Dependency Injection with Hilt for Android (Kotlin)
![Mastering Hilt - Android | Kotlin | Hilt (Dagger 2) [ Part 1]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1697040117756%2F2015f3f5-27b6-49f9-b9b0-02ac228b5e4c.jpeg&w=3840&q=75)
Senior Android Engineer from Bangladesh. Love to contribute in Open-Source. Indie Music Producer.
Search for a command to run...
Becoming Proficient in Dependency Injection with Hilt for Android (Kotlin)
![Mastering Hilt - Android | Kotlin | Hilt (Dagger 2) [ Part 1]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1697040117756%2F2015f3f5-27b6-49f9-b9b0-02ac228b5e4c.jpeg&w=3840&q=75)
Senior Android Engineer from Bangladesh. Love to contribute in Open-Source. Indie Music Producer.
No comments yet. Be the first to comment.
This course focuses on mastering Dependency Injection (DI) using Hilt, a widely used library in Android development.
Becoming Proficient in Dependency Injection with Hilt for Android (Kotlin)
A practical guide to choosing the right coroutine primitive for your Android/Kotlin projects

This guide explains what Channels are, when to use them, how to use them correctly, and when NOT to use them — in simple, professional language. 1. What problem do Channels solve? In Kotlin coroutines, you often have multiple coroutines running at t...

Learn how to build preview-safe ViewModels in Jetpack Compose using Hilt.

HandlerInterceptor vs Filter in Spring Boot: A Practical Guide with JNDI Injection Prevention

Simple In-Memory Caching: A Tiny Trick with Massive Impact

Setting up Gradle
Application Class Configuration
To get started with Hilt in your Android project using Kotlin, follow these steps for setting up Gradle and configuring the Application class:
Setting up Gradle:
In our project's build.gradle file, make sure we have the necessary dependencies for Hilt:
buildscript {
// ...
dependencies {
// ...
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40.5"
}
}
allprojects {
repositories {
// ...
mavenCentral()
}
}
In our app's build.gradle file, apply the Hilt plugin and add the Hilt dependencies:
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
// ...
}
dependencies {
// ...
implementation "com.google.dagger:hilt-android:2.40.5"
kapt "com.google.dagger:hilt-android-compiler:2.40.5"
}
Application Class Configuration:
In our Application class, add the @HiltAndroidApp annotation to enable Hilt for our application:
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MyApplication : Application() {
// Application code
}
With these setup steps, we have configured Hilt for your Android application. The @HiltAndroidApp annotation in the Application class tells Hilt to generate and manage the necessary components to enable dependency injection throughout our app.
Now you can start using Hilt annotations, such as @AndroidEntryPoint, to enable dependency injection in our activities, fragments, view models, and other Android components. Hilt will take care of creating and managing the necessary dependencies for us.