dagger: Hilt: More meaningful error messages
First of all, Hilt looks like a really promising project, keep up the good work!
One feature I would like to see is more meaningful error messages at run time and compile time. For instance, one error I always seem to get is:
Caused by: java.lang.ClassCastException: com.mypackage.DaggerMainApplication_HiltComponents_ApplicationC$ActivityRetainedCImpl$ActivityCImpl cannot be cast to com.com.mypackage.MyActivity_GeneratedInjector
This runtime exception basically means that there is an error in the dependency graph meaning something can’t be injected, but it would be nice to know what exactly.
Even better, if this problem could be caught and displayed at compile time, then fantastic 😃
kind regards, goldy1992
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 21 (5 by maintainers)
@Chang-Eric, is it expected to occur in below scenario?
:ui-component module - ‘com.android.library’ :profile module - ‘com.android.library’
:app module - ‘com.android.application’
In the above project, I have my Application class in :ui-component module.
And my Activity is in :profile module.
But when I run this app, I get below exception at runtime.
What could go wrong here? And why it’s a runtime error instead of compile time?
i just got an error and all it said was [Hilt] lol
@Chang-Eric Regarding that error, I should mention that it was very much resolved by manually doing a gradle build before running the application in Android Studio. There was actually a compile time error. This leads me to believe that there is an issue with Android Studio not rebuilding some Hilt (dagger) code that has changed since the last deployment.
Hey, I just add the same issue. In my project, I have an interface
Logger
used to log stuffs, and its implementationTimberLogger
(injected via constructor)TimberLogger
is provided using a module:When building with Android Studio, the application crashes with at runtime with this stacktrace:
(It’s broken on all latest AS version for each track.)
While building it manually with the gradle wrapper works just fine.
@ChanSek IIUC, it would have to be the opposite. In particular,
:ui-component
contains the@HiltAndroidApp
, so it would have to have a dependency on:profile
.