【问题标题】:SingletonComponent is missing a parent declarationSingletonComponent 缺少父声明
【发布时间】:2021-02-05 00:46:34
【问题描述】:

我刚刚将我的 android Hilt-Dagger 依赖更新为 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)

提前致谢。

【问题讨论】:

    标签: android dagger-hilt


    【解决方案1】:

    尝试将您的 hilt-android-compiler 更新为

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

    您可以导入 SingleComponent 类,但 kapt 无法正确处理它。

    hilt 版本和 kapt 版本匹配很重要。这是我目前的设置。

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

    【讨论】:

    • 可以确认,此解决方案有效。你的 kapt 版本和实现版本不应该不同。
    • 更新后出现这个错误:error: method getActivityFactory in class DefaultViewModelFactories cannot be applied to given types; return DefaultViewModelFactories.getActivityFactory(this);
    【解决方案2】:

    当 Android Studio 建议将 hilt 从 2.28 升级到 2.31 时,这发生在我身上。但它没有建议 kapt。确保两者都是 2.31。

    【讨论】:

      【解决方案3】:

      在我的情况下,为@mikeBlack 和@user2343647 答案增加价值。确保所有三个都更新到相同的版本号。模块级 build.gradle

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

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

      和项目级 build.gradle

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

      用最新版本替换 2.36。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-04
        • 2013-07-11
        • 2013-11-13
        • 1970-01-01
        • 1970-01-01
        • 2016-05-04
        相关资源
        最近更新 更多