Search code examples
androiddagger-hilt

whats the difference between these gradle deps for and dagger/hilt compilers


I am confused about when and where to use the following android dagger hilt gradle dependencies

"com.google.dagger:dagger-compiler"
"com.google.dagger:hilt-compiler"
"com.google.dagger:hilt-android-compiler"
"androidx.hilt:hilt-compiler"

do i need to use them all in my android project? what does each one do?


Solution

  • First it depends on the scenario you have in your project.

    "com.google.dagger:dagger-compiler" - This you can use if you are using dagger as dependency injector in your project.

    "com.google.dagger:hilt-compiler" or "com.google.dagger:hilt-android-compiler" - From both you can use any one out of two , while using Hilt as dependency injector in your project. In some documents you will find first one and in some you'll find second one .

    "androidx.hilt:hilt-compiler" - This is an additional dependency , it is added when you want to enable dependency injection of certain classes from the androidx libraries. It is added with addition to the dependency of hilt or dagger whatever you are using in your project.

    **You have to remember Hilt is the successor of dagger and it's jetpack recommended. **

    Links to check further - Using Hilt With Jetpack Library Google Dagger Dependency List