简体   繁体   中英

Error: @dagger.android.ContributesAndroidInjector was used, but dagger.android.processor.AndroidProcessor was not found

I am trying to setup Dagger 2.12 and I'm getting this error:

error: @dagger.android.ContributesAndroidInjector was used, but dagger.android.processor.AndroidProcessor was not found on the processor path

Here's how I've configured Dagger:

My Application class:

public final class App extends android.app.Application implements HasActivityInjector {

    @Inject
    DispatchingAndroidInjector<Activity> activityInjector;

    @Override
    public void onCreate() {
        super.onCreate();
        DaggerAppComponent.builder().build().inject(this);
    }

    @Override
    public AndroidInjector<Activity> activityInjector() {
        return activityInjector;
    }
}

ActivityBindingModule:

@Module
public abstract class ActivityBindingModule {

    @ContributesAndroidInjector(modules = SearchActivityModule.class)
    abstract SearchActivity searchActivity();
}

SearchActivityModule:

@Module
public class SearchActivityModule {

    @Provides
    public SearchActivityDelegate getDelegate(SearchActivity searchActivity) {
        return searchActivity;
    }

    @Provides
    public SearchActivityPresenter providePresenter(SearchActivity searchActivity) {
        return new SearchActivityPresenter(new OtherDependency(), searchActivity);
    }
}

AppModule:

@Module(includes = { AndroidInjectionModule.class, ActivityBindingModule.class })
public abstract class AppModule {

}

Does anyone know what could be causing this error?

Go to your module level build.gradle , under

annotationProcessor 'com.google.dagger:dagger-android-processor:[YOUR VERSION NUMBER]' ,

add:

kapt 'com.google.dagger:dagger-android-processor:[YOUR VERSION NUMBER]' .

可能您会错过以下依赖项。

annotationProcessor 'com.google.dagger:dagger-android-processor:' + yourDaggerVersion

the only solution for me was using old version of dagger (2.16)

kotlin version : 1.2.71
// dagger
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt "com.google.dagger:dagger-compiler:2.16"
kapt "com.google.dagger:dagger-android-processor:2.16"

For Java

Add this to your build.gradle

annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"

For Kotlin

Add this to your build.gradle

apply plugin: 'kotlin-kapt'

 kapt "com.google.dagger:dagger-android-processor:$dagger_version"

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