Reputation: 4009
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
Upvotes: 20
Views: 30907
Reputation: 7210
my problem was with duplicate
packages
and files like (ViewModel 2)
.
Just delete it and clean, rebuild project.
Upvotes: 4
Reputation: 221
check if your all files have specificated the package -> "package com.something.blahblah...."
Upvotes: 13
Reputation: 3189
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.
Upvotes: 0
Reputation: 2556
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.
Upvotes: 0
Reputation: 460
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'
Upvotes: 0
Reputation: 678
Adding annotationProcessor "com.google.dagger:dagger-android-processor:2.11"
to your gradle file will resolve your problem.
Upvotes: 27
Reputation: 79
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
Upvotes: 1
Reputation: 13027
For Kotlin, instead of
annotationProcessor com.google.dagger:dagger-android-processor:2.11
use
kapt com.google.dagger:dagger-android-processor:2.11
Upvotes: 8
Reputation: 28748
In my case SomeModule
class contained unnecessary lines:
@ContributesAndroidInjector
internal abstract fun fragmentInjector(): SomeFragment
Upvotes: 4