Android Dagger2 ComponentProcessor was unable to process

Irc*_*ver 5 android kotlin dagger-2

I'm trying to make multi module project with Dagger2. You can see my code following the link. In the main branch is working solution where all the dagger classes are in presentation module.

Now I'm trying to make separate app module for the DI root. You can see the latest attempts in the develop branch. It's not working. I want to make my root ApplicationComponent component in app module and add there PresentationComponent (sub)component from other module. Every time I try something, eventually I get following:

dagger.internal.codegen.ComponentProcessor was unable to process 'ru.ircover.schultetables.app.ApplicationComponent' because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code

这很奇怪,因为与分支相比,我没有更改任何依赖项main。唯一改变的是从根组件ApplicationComponent到子组件的新链接PresentationComponent。据我了解,没有办法将循环依赖显示为app模块,并且其内容在模块中不可见presentation。我已经遵循了我在谷歌上遇到的所有教程,但没有一个有帮助。

我已经尝试过的:

  1. 添加到子组件的根组件 getter。
  2. 添加到根组件BuilderFactory子组件。
  3. 使用链接添加到根组件特殊模块subcomponent
  4. inject子组件的方法移至父组件。

现在我被困住了。问题似乎出在组件或模块连接中的某个地方,但我无法找到它发生的位置和方式。我这里需要帮助。

小智 11

根据谷歌文档,你可以这样做:

  1. @HiltViewModel给类添加注解

  2. @ViewModelInject将构造函数上的注释替换为@Inject.

  3. @Assisted从构造函数参数中删除SavedStateHandle- 如果存在

  4. androidx.hilt:hilt-lifecycle-viewmodelbuild.gradle文件中删除旧的依赖项

  • 谢谢,删除数字 4 对我来说很有效。 (2认同)

小智 1

我已经成功地通过这些更改构建了您的项目:

  1. 左边是一个演示文稿,右边是一个应用程序,如您所见,我已经删除了 dagger-android,并将 moxy deps 作为 API(因为您的应用程序是一个主模块,它必须查看要构建的所有 deps图表),或者您可以将 moxy deps 添加到应用程序在此输入图像描述
  2. 之后,不会有任何匕首警告,但您需要修复一些文件才能完成构建。顺便说一句,将某些内容传递给模块的构造函数是一种不好的且不推荐的做法。正如您在PresentationModule中看到的,我删除了构造函数并删除了provideContext。我将 Context 绑定移至 ApplicationComponent - 这是执行此操作的好且正确的位置。在此输入图像描述
  3. 我还从PresentationComponent.Factory.create中删除了构造函数参数在此输入图像描述