简体   繁体   中英

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

annotationProcessor "com.google.dagger:dagger-android-processor:2.11"到您的 gradle 文件将解决您的问题。

In my case SomeModule class contained unnecessary lines:

@ContributesAndroidInjector
internal abstract fun fragmentInjector(): SomeFragment

For Kotlin, instead of

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

use

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

如果建议的解决方案都不起作用,请检查您是否忘记向任何依赖项添加 @Provides 注释,这就是我的问题

检查您的所有文件是否都指定了包->“包 com.something.blahblah ....”

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

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'

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM