SingletonComponent缺少父声明
我刚刚更新我的Android希尔特匕首的依赖关系到1.0.0-alpha03
和我身材ApplicationComponent被弃用
,取而代之的
,但一旦我在我的代码替换它显示了这个错误我是否需要做别的任何事情,只是用它?SingletonComponent
完全错误
> 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)
提前致谢。
回答
尝试将您的 hilt-android-compiler 更新为
kapt "com.google.dagger:hilt-android-compiler:2.37"
您可以导入 SingleComponent 类,但 kapt 无法正确处理它。
刀柄版本和 kapt 版本匹配很重要。这是我目前的设置。
// HILT
def hilt_version = "2.37"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
回答
当 Android Studio 建议将 hilt 从 2.28 升级到 2.31 时,这发生在我身上。但它没有建议 kapt。确保两者都是 2.31。