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
Adding annotationProcessor "com.google.dagger:dagger-android-processor:2.11"
to your gradle file will resolve your problem.
check if your all files have specificated the package -> "package com.something.blahblah...."
For Kotlin, instead of
annotationProcessor com.google.dagger:dagger-android-processor:2.11
use
kapt com.google.dagger:dagger-android-processor:2.11
In my case SomeModule
class contained unnecessary lines:
@ContributesAndroidInjector
internal abstract fun fragmentInjector(): SomeFragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With