Dagger 2: inject an interface in a constructor

By following code:


    MainPresenter provideMainPresenter(MainView mainView) {
        return new MainPresenter(mainView);
    }

You are telling dagger: "hey, whenever I ask you to inject MainPresenter, construct it using MainView". But dagger complaints, because you haven't specified how exactly he should build/acquire MainView.

So, in your PresenterModule do this:


    @Module
    public class PresenterModule {

        MainView mainView;

        public PresenterModule(MainView mainView) {
            this.mainView = mainView;
        }

        @Provides
        MainPresenter provideMainPresenter() {
            return new MainPresenter(mainView);
        }

    }

Then when building the component:


    DaggerPresenterComponent.builder()
                            .presenterModule(new PresenterModule(this))
                            .build();