Dagger Hilt Tutorial — Step by Step Guide Part (2/2)
So you made through first post huh? If not I will suggest you to read it first if you have no idea about what is dagger hilt.
So without wasting much time lets get start.
Here is what we gonna do.
- Make a cup of coffe
- Create new project
- In project level build.gradle
- In app level build.gradle
- Create new class that extend application class
- In AndroidManifest.xml
- Create new class for dagger hilt object
- In activity_main.xml and MainActivity.java
- Output
- TL;DR
Lets get start one by one.
1.I know you won’t do.
2.create new project and name it whatever you want.
3.In project level build.gradle. add dagger hilt dependency
4.In app level build.gradle
- if you are using older version add apply plugin,glide library and dagger hilt
- If you are using new version
And then add dependency in build.gradle file
5.Create new class called HiltApplication that extend application class.
make sure you add annotation @HiltAndroidApp and extend application class.
6.In AndroidManifest.xml
Add application name in name tag inside application and add internet permission too.
7.Create new class AppModule.java for dagger hilt object.
In this example we are using @SingletonComponent so that object will be used throughout the application.
@Module : Represent class is part of module
In this case we will use glide library to load image from the application.
8.In activity_main.xml and MainActivity.java
- In activity_main.xml
- In MainActivity.java
9. Output
10.TL;DR
- Dagger is a fully static, compile-time dependency injection framework for both Java and Android.
- It is developed by the Java Core Libraries Team at Google.
- It make our life lot easier with help of dependency injection
Thanks guys, I hope you like this blog. please make sure to give clap 👏 and leave some engagement.