gpt4 book ai didi

Android Dagger2 ComponentProcessor 无法处理

转载 作者:行者123 更新时间:2023-12-05 01:25:54 24 4
gpt4 key购买 nike

我正在尝试使用 Dagger2 制作多模块项目。你可以看到我的代码following the link .在 main 分支中是工作解决方案,其中所有 Dagger 类都在 presentation 模块中。

现在我正在尝试为 DI 根创建单独的 app 模块。可以看到最新的尝试in the develop branch .它不工作。我想在 app 模块中创建我的根 ApplicationComponent 组件,并在其中添加来自其他模块的 PresentationComponent (子)组件。每次我尝试一些东西,最终我都会得到以下结果:

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 方法移动到父组件。

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

最佳答案

基于 Google documentation你可以这样做:

1- 给类添加@HiltViewModel 注解

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

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

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

关于Android Dagger2 ComponentProcessor 无法处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70620088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com