Search code examples
androiddependency-injectiondagger-2

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

Solution

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