I'm currently using hilt in a single gradle module...
# dagger
c
I'm currently using hilt in a single gradle module application. Everything works great. Now I added a new module called featureX. featureX contains a ChatActivity and ChatViewModel. I also want to use dependency injection in this new gradle module. In my app module I added
Copy code
implementation(project(":featureX"))
then to featureX build.gradle.kts I added
Copy code
kotlin("kapt")
id("dagger.hilt.android.plugin")
and
Copy code
implementation("com.google.dagger:hilt-android:2.35.1")
kapt("com.google.dagger:hilt-compiler:2.35.1")
If I build the app and navigate to ChatActivity. Everything works fine. As expected, I'm not introducing DI yet. I add a new class to featureX
Copy code
class Blah @Inject constructor() {
    fun getName(): String {
        return "x"
    }
}
run. Compiles. As expected. Then I go to ChatActivity (my only activity in featureX)
Copy code
@AndroidEntryPoint
class ChatActivity : AppCompatActivity() {
    @Inject lateinit var blah: Blah
compiles, but crashes at Runtime.
Copy code
Caused by: java.lang.ClassCastException: com.rollertoaster.app.DaggerRollerToasterApplication_HiltComponents_SingletonC$ActivityRetainedCImpl$ActivityCImpl cannot be cast to com.rollertoaster.featureX.ChatActivity_GeneratedInjector
Ideas? It's my first time using multi modules and I'm not great at dagger/hilt and so maybe I'm making a noob mistake here. EDIT: Clean and rebuild fixed it. 😭
🤪 3