com.hi.app.presenter.contract.AccountContract.IAccountPresenter cannot be provided without an @Provides- or @Produces-annotated method.
产生这个错误的原因之一:
@Component(modules = LoginContractModule.class)
public interface AccountActivityComponent {
void inject(AccountActivity accountActivity);
}
这里传入的modules是传错了,传入了其它的不相关的module,引起这样的编译错误,其实
DaggerAccountActivityComponent
.builder()
.accountContractModule(new AccountContractModule(this))
.build()
.inject(this);
进入编译出来的 "DaggerAccountActivityComponent" 代码里就可以大概看出来引起混乱的不相关的类。
本文解析了一个关于Dagger2依赖注入的常见错误:com.hi.app.presenter.contract.AccountContract.IAccountPresenter cannot be provided without an @Provides-or @Produces-annotated method. 通过检查错误的模块传递,发现是由于传入了错误的模块导致的编译错误。正确的做法是在Dagger AccountActivityComponent中精确指定AccountContractModule。

2303

被折叠的 条评论
为什么被折叠?



