'Android Dagger2 ComponentProcessor was unable to process

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

It's very strange as I didn't change any dependencies in comparison with main branch. The only thing changed - new link from root component ApplicationComponent to child PresentationComponent. As I understand it, there is no way to appear circular dependency as app module and its content is not visible in presentation module. I've followed all the tutorials I've met in google, but none of them helped.

What I've already tried:

  1. Add to root component getter of subcomponent.
  2. Add to root component Builder or Factory of subcomponent.
  3. Add to root component special module with subcomponent link.
  4. Move inject methods of child component to the parent.

Now I'm stuck. It seems that the problem is somewhere in components or modules connection, but I can't manage to find where and how it happened. I need help here.



Solution 1:[1]

I've managed to build your project with these changes:

  1. To the left is a presentation, to the right is an app, as you can see, I've removed dagger-android, AND make moxy deps as API (because your app is a main module, it has to see all deps to build a graph), or you can just add moxy deps to the appenter image description here
  2. and after that, there won't be any dagger warning, but you need to fix some of your files to complete the build. Btw, to pass something to module's constructor is a bad and deprecated practice. As you can see in PresentationModule I removed constructor and removed provideContext. And I moved a Context binding to the ApplicationComponent - it is the good and right place to do it. enter image description here
  3. And I also removed constructor parameter from PresentationComponent.Factory.create enter image description here

Solution 2:[2]

You'll need to add the dagger.android support libraries, since your moxy.MvpAppCompatFragment is built on Android Support Fragments. Add this to your presentation gradle file:

implementation "com.google.dagger:dagger-android:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"

From your develop branch's presentation/build.gradle:

implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
kapt "com.google.dagger:dagger-android-processor:$dagger_version"

From the Gradle setup:

If you're using classes in dagger.android you'll also want to include:

implementation 'com.google.dagger:dagger-android:2.x'
implementation 'com.google.dagger:dagger-android-support:2.x' // if you use the support libraries
annotationProcessor 'com.google.dagger:dagger-android-processor:2.x'

Solution 3:[3]

Based on Google documentation you can do this:

1- Add @HiltViewModel annotation to the class

2- Replace the @ViewModelInject annotation on the constructor with @Inject.

3- Remove @Assisted from the SavedStateHandle constructor parameter, if it exists

4- Remove the old androidx.hilt:hilt-lifecycle-viewmodel dependency from your build.gradle file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Grigoriym
Solution 2
Solution 3 mojtaba mohammadian