20

I was testing new feature of dagger: Android module. And I am not able to compile the code when I use @ContributesAndroidInjector I am always getting following error:

Error:(12, 8) error: dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.

I tried to implement my components like here, but still I got the error.

Here is the smallest example:

@PerApplication
@Component(modules = {AndroidInjectionModule.class, LoginBindingModule.class})
public interface ApplicationComponent {
    void inject(ExampleApplication application);
}

@Module
public abstract class LoginBindingModule {
    @ContributesAndroidInjector
    abstract LoginActivity contributeYourActivityInjector();
}

public class LoginActivity extends Activity {

    @Inject
    LoginPresenter loginPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        AndroidInjection.inject(this);
        super.onCreate(savedInstanceState);
    }
}

public class LoginPresenter {

    @Inject
    public LoginPresenter() {

    }
}

If I remove LoginBindingModule from ApplicationComponent the app would be build, but would fail with runtime exception:

java.lang.IllegalArgumentException: No injector factory bound for Class

project setup:

gradle 3.3
buildToolsVersion "25.0.2"
dagger 2.11
Rostyslav Roshak
  • 3,859
  • 2
  • 35
  • 56
  • 2
    Please take a look at this sample: https://material.uplabs.com/posts/daggerandroidinjector I had the same issue as you but I was missing the annotationProcessor "com.google.dagger:dagger-android-processor:2.11" in the gradle file. – exkoria Jun 21 '17 at 12:22
  • 1
    You did not provide your `ExampleApplication` in your code example. If you want to use `AndroidInjection.inject(Activity)`, you have to have your application implement `HasActivityInjector`. I tried your code and it seems to be working fine. If you continue to see the error, then it doesn't come from the code you posted. Post the whole project somewhere if you need more help. Also, have you tried cleaning/rebuilding your project. – Andrey Makarov Jun 27 '17 at 08:48

9 Answers9

27

Adding annotationProcessor "com.google.dagger:dagger-android-processor:2.11" to your gradle file will resolve your problem.

Samuel Peter
  • 4,136
  • 2
  • 34
  • 42
Patrick
  • 678
  • 8
  • 16
13

check if your all files have specificated the package -> "package com.something.blahblah...."

Sarojini2064130
  • 221
  • 3
  • 7
8

For Kotlin, instead of

annotationProcessor com.google.dagger:dagger-android-processor:2.11

use

kapt com.google.dagger:dagger-android-processor:2.11
Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
4

In my case SomeModule class contained unnecessary lines:

@ContributesAndroidInjector
internal abstract fun fragmentInjector(): SomeFragment
CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • What does that mean? – Rishabh Dhiman Jul 11 '21 at 16:37
  • It means that I got this error message and found these 2 lines, then removed them. There are many reasons to get the error, this is one of them. – CoolMind Jul 11 '21 at 19:09
  • @RishabhDhiman, It means that I got this error message and found these 2 lines, then removed them. There are many reasons to get the error, this is one of them. – CoolMind Aug 04 '21 at 12:43
4

my problem was with duplicate packages and files like (ViewModel 2). Just delete it and clean, rebuild project.

Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
1

if none of the suggested solutions works, just check if you have forgot to add @Provides annotations to any of the dependencies, this was the issue in my case

0

I had the same error but the problem was with the module (project) where I declared the Dagger module. Make sure you add the kotlin-kapt plugin otherwise Dagger won't be able to generate any class.

// declare it at the top of your build.gradle file
apply plugin: 'kotlin-kapt'
gyosida
  • 450
  • 4
  • 17
0

I've had a very weird error when converting a Module file to Kotlin. It might be rare, but maybe someone else stumbles across the same problem:

My Dagger module is part of a Gradle module. It uses dependencies which only have an api Gradle configuration. Dagger generates Stub (Java) files for every Kotlin class involved. Without those Subs everything worked. With those Stubs it gave the above error. Adding all missing dependencies to the Gradle module was the solution for me.

dipdipdip
  • 2,326
  • 1
  • 21
  • 31
0

I had the same issue and accepted answer not worked for me. After a lot of analysis, I find the issue is pointing to some other library, in my case butterknife. I had a layout variable in my Dagger enabled activity called editLenearLayout as below.

@BindView(R.id.ll_edit11)
    LinearLayout editLenearLayout;

When I removed these two lines of codes surprisingly it worked :) And the problem was Butterknife unable to bind id inside < include> layout. But the exiting factor is Studio showed following error.

error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.

My Linearlayout had came inside < include> layout. pointing to this problem.

May save someone's day.

Ebin Joy
  • 2,690
  • 5
  • 26
  • 39