19

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?

vinS
  • 1,417
  • 5
  • 24
  • 37
Micah Simmons
  • 2,078
  • 2
  • 20
  • 38
  • Do you have in your gradle file `annotationProcessor 'com.google.dagger:dagger-android-processor:2.12'` ? – GVillani82 Dec 10 '17 at 14:02
  • Thanks for your response. Yes, I have this dependency in my build.gradle `annotationProcessor 'com.google.dagger:dagger-android-processor:2.12'`. – Micah Simmons Dec 10 '17 at 14:03
  • I'm having the same issue. Have you had any luck with it? – FMontano Dec 27 '17 at 19:51
  • 1
    In my case, I am using Kotlin. I was able to get rid of the problem by replacing `annotationProcessor "com.google.dagger:dagger-compiler:${daggerVersion}"` with `kapt "com.google.dagger:dagger-compiler:${daggerVersion}"` How does your app/build.gradle looks like? – FMontano Dec 27 '17 at 20:46
  • Any fixes? I just came across the same issue. – Abhriya Roy Feb 04 '18 at 05:00
  • I think that the problem was caused by Dagger related Gradle dependencies not being configured correctly. – Micah Simmons Feb 04 '18 at 11:08

4 Answers4

49

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]'.

Sam W.
  • 694
  • 6
  • 6
8

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"
issamux
  • 1,336
  • 1
  • 19
  • 35
  • Faced with same issue - after update Dagger from 2.16 to 2.17 it shows error `Activity cannot be provided without an @Inject constructor or an @Provides-annotated method`, but I have @ContributesAndroidInjector for this Activity. Was you able to solve it with latest Dagger version? – anber Nov 26 '18 at 11:03
7

Probably you would have missed the following dependency.

annotationProcessor 'com.google.dagger:dagger-android-processor:' + yourDaggerVersion
gopalanrc
  • 254
  • 3
  • 11
6

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"
Prakash Shukla
  • 165
  • 2
  • 7