Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dagger @ContributesAndroidInjector ComponentProcessor was unable to process this interface

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
like image 358
Rostyslav Roshak Avatar asked Jun 19 '17 17:06

Rostyslav Roshak


4 Answers

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

like image 158
Patrick Avatar answered Nov 17 '22 21:11

Patrick


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

like image 29
Sarojini2064130 Avatar answered Nov 17 '22 22:11

Sarojini2064130


For Kotlin, instead of

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

use

kapt com.google.dagger:dagger-android-processor:2.11
like image 7
Misha Akopov Avatar answered Nov 17 '22 23:11

Misha Akopov


In my case SomeModule class contained unnecessary lines:

@ContributesAndroidInjector
internal abstract fun fragmentInjector(): SomeFragment
like image 4
CoolMind Avatar answered Nov 17 '22 23:11

CoolMind