SingletonComponent is missing a parent declaration

Viewed 5915

I have just updated my android Hilt-Dagger dependences to 1.0.0-alpha03
and I figure that ApplicationComponent is deprecated
and replaced with SingletonComponent
but once I replace it at my code it shows up this error Am I need to do anything else except replacing it?

Full Error

> Task :app:kaptDebugKotlin FAILED
error: [Hilt]
  @DefineComponent dagger.hilt.components.SingletonComponent is missing a parent declaration.
  Please declare the parent, for example: @DefineComponent(parent = ApplicationComponent.class)
  [Hilt] Processing did not complete. See error above for details.error: [Hilt]
  @DefineComponent dagger.hilt.components.SingletonComponent is missing a parent declaration.
  Please declare the parent, for example: @DefineComponent(parent = ApplicationComponent.class)
  [Hilt] Processing did not complete. See error above for details.error: [Hilt]
  @DefineComponent dagger.hilt.components.SingletonComponent is missing a parent declaration.
  Please declare the parent, for example: @DefineComponent(parent = ApplicationComponent.class)
  [Hilt] Processing did not complete. See error above for details.error: [Hilt]
  @DefineComponent dagger.hilt.components.SingletonComponent is missing a parent declaration.
[Hilt]

  Please declare the parent, for example: @DefineComponent(parent = ApplicationComponent.class)
  [Hilt] Processing did not complete. See error above for details.

Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

Thanks in advance.

3 Answers

Try updating your hilt-android-compiler to

kapt "com.google.dagger:hilt-android-compiler:2.37"

You're able to import the SingleComponent class, but kapt is failing to process it correctly.

It's important that both the hilt version and the kapt version match. Here is my current setup.

// HILT
def hilt_version = "2.37"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"

This happened to me when Android studio suggested an upgrade of hilt to 2.31 from 2.28. But it did not suggest for the kapt. Make sure both are 2.31.

In my case, adding value to @mikeBlack and @user2343647 answer. Make sure that all the three are updated to same version number. Module level build.gradle

implementation "com.google.dagger:hilt-android:2.36"

kapt "com.google.dagger:hilt-android-compiler:2.36"

and Project level build.gradle

classpath "com.google.dagger:hilt-android-gradle-plugin:2.36"

Replace 2.36 with latest version.

Related