【发布时间】:2017-10-20 08:42:27
【问题描述】:
我正在配置新的 Dagger Android 模块,但出现此错误 这是我的组件:
@AppScope
@Component(modules = {AppModule.class, NetModule.class})
public interface AppComponent {
@Component.Builder
interface Builder {
@BindsInstance
Builder application(ExampleApplication application);
@BindsInstance
Builder appModule(AppModule appModule);
@BindsInstance
Builder netModule(NetModule netModule);
AppComponent build();
}
void inject(ExampleApplication __);
...
我在我的应用程序中这样构建
appComponent = DaggerAppComponent
.builder()
.application(this)
.appModule(new AppModule(this))
.netModule(new NetModule())
.build()
.inject(this);
但我仍然收到错误
错误:(20, 3) 错误:@Component.Builder 缺少所需模块或组件的设置器:[app.example.com.dagger.AppModule]
根据应该是正确的文档,我错过了什么?
例如,这可能是带有 Builder 的有效组件:
@Component(modules = {BackendModule.class, FrontendModule.class})
interface MyComponent {
MyWidget myWidget();
@Component.Builder
interface Builder {
MyComponent build();
Builder backendModule(BackendModule bm);
Builder frontendModule(FrontendModule fm);
}
}
【问题讨论】:
-
您是否尝试过在您的模块方法中不使用
@BindsInstance? -
@DavidMedenjak 我正在关注这个tutorial 哪个模块应该有这个?应用模块?
-
如果你看看你上面提供的代码,一个是你自己的,另一个是匕首文档的一部分。明显的区别是,you 在您的
AppModule和NetModule构建器方法上有一个@BindsInstance注释。 -
我也遇到了同样的问题
标签: java android dependency-injection dagger-2