Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SingletonComponent is missing a parent declaration

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.

like image 661
Adham Gamal Avatar asked Feb 05 '21 00:02

Adham Gamal


2 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"
like image 151
mikeBlack Avatar answered Oct 08 '22 02:10

mikeBlack


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.

like image 6
user2343647 Avatar answered Oct 08 '22 02:10

user2343647