Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 671
Micah Simmons Avatar asked Dec 10 '17 13:12

Micah Simmons


People also ask

What is ContributesAndroidInjector?

Annotation Type ContributesAndroidInjectorThe injector is implemented with a Subcomponent and will be a child of the Module 's component. This annotation must be applied to an abstract method in a Module that returns a concrete Android framework type (e.g. FooActivity , BarFragment , MyService , etc).

Is dagger Android deprecated?

It's officially deprecated and you can pretty much ignore it. Google's framework, which became dominant in Android ecosystem, was originally called Dagger 2. Sometimes we still refer to it as such, but, in most cases, we simply call it Dagger today.

What is DaggerApplication?

Class DaggerApplicationAn Application that injects its members and can be used to inject Activity s, Fragment s, Service s, BroadcastReceiver s and ContentProvider s attached to it. Injection is performed in onCreate() or the first call to AndroidInjection.

What is dagger compiler?

Dagger is a compile-time framework for dependency injection. It uses no reflection or runtime bytecode generation, does all its analysis at compile-time, and generates plain Java source code. Dagger is actively maintained by the same team that works on Guava.


2 Answers

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

like image 191
Sam W. Avatar answered Oct 02 '22 18:10

Sam W.


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"
like image 44
issamux Avatar answered Oct 02 '22 19:10

issamux