java.lang.RuntimeException: Hilt classes generated from @HiltAndroidTest are missing

Solution 1:

You have missed this

kaptTest 'com.google.dagger:hilt-android-compiler:2.28-alpha'

from your dependencies..

source : https://developer.android.com/training/dependency-injection/hilt-testing

dependencies {
    // For Robolectric tests.
    testImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha'
    // ...with Kotlin.
    👉👉👉👉👉 kaptTest 'com.google.dagger:hilt-android-compiler:2.28-alpha'
    // ...with Java.
    testAnnotationProcessor 'com.google.dagger:hilt-android-compiler:2.28-alpha'

    // For instrumented tests.
    androidTestImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha'
    // ...with Kotlin.
    kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.28-alpha'
    // ...with Java.
    androidTestAnnotationProcessor 'com.google.dagger:hilt-android-compiler:2.28-alpha'
}

Solution 2:

To make Dagger Hilt works normally with Robolectric. Please make sure you have the following conditionals:

  • Have kaptTest 'com.google.dagger:hilt-android-compiler:...' from your dependencies.
  • Have @HiltAndroidTest in your test class.
  • Have @Config(application = HiltTestApplication::class) in your test class or specify which application to use in the robolectric.properties file: application=dagger.hilt.android.testing.HiltTestApplication