https://kotlinlang.org logo
#dagger
Title
# dagger
s

Sanendak

11/01/2021, 4:51 PM
Hello everyone! I want to create library, but already using Hilt in lib classes. Q: How to create library that doesn't need Hilt/Dagger from other developers? Hilt needs Application class and that is the main problem.
a

Ahmed Ibrahim

11/02/2021, 9:26 AM
I don't think that Hilt supports being used inside an SDK or library, as you've mentioned the main problem is that you don't have access to the host app's Application class that has to be setup for Hilt. So I guess the only solution is to use vanilla Dagger and make it as an implementation details of your library
s

Sanendak

11/02/2021, 9:44 AM
Thanks, @Ahmed Ibrahim! I also thought about such a solution, but I wanted to simplify the task.
a

Ahmed Ibrahim

11/02/2021, 9:46 AM
If your library will have many Fragments/Activities, there's also the possibility of using dagger-android without an Application class, but that requires a deep understanding on how Dagger-Android works, and don't advice that route unless you know what you're doing.
2 Views