[英]Dagger2 issue with “cannot be provided without an @Provides-annotated method.”
I'm trying to setup a new project with Dagger2, I've used Dagger2 before, but now I'm trying to set it up from scratch by myself. 我正在尝试用Dagger2设置一个新项目,之前我使用过Dagger2,但现在我正试图自己设置它。 I'm getting the example from a Kotlin project that I'm part of, but can't set it up for Java the same way as it works in Kotlin right now (or maybe I'm missing something).
我从Kotlin项目中得到了一个例子,但我不能像现在在Kotlin中那样设置Java(或者我可能缺少一些东西)。
It's just a single Component, single Module and Application. 它只是一个组件,单个模块和应用程序。
Component 零件
@Singleton
@Component(modules = {MainAppModule.class})
public interface AppComponent extends AndroidInjector<App> {
@Component.Builder
abstract class Builder implements AndroidInjector.Factory<App> {
public AppComponent create(App application) {
seedApplication(application);
return build();
}
@BindsInstance
abstract void seedApplication(App application);
abstract AppComponent build();
}
}
Module 模
@Module
abstract class MainAppModule {
@Binds
abstract public Application bindApplication(App application);
@ContributesAndroidInjector
abstract public MainActivity contributeActivityInjector();
}
*Application * *申请*
public class App extends DaggerApplication {
@Override
public AndroidInjector<? extends DaggerApplication> applicationInjector() {
return DaggerAppComponent.builder().create(this);
}
}
At this point I don't have any classes that I call with @Inject
I'm just getting error at build time: 在这一点上,我没有使用
@Inject
调用的任何类,我只是在构建时遇到错误:
error: [dagger.android.AndroidInjector.inject(T)] java.util.Map<java.lang.Class<? extends android.content.BroadcastReceiver>,javax.inject.Provider<dagger.android.AndroidInjector.Factory<? extends android.content.BroadcastReceiver>>> cannot be provided without an @Provides-annotated method.
public interface AppComponent extends AndroidInjector<App> {
^
Of course cannot be provided without an @Provides-annotated method.
当然,
cannot be provided without an @Provides-annotated method.
seems to be the problem, but I just don't know how to solve it. 似乎是问题,但我只是不知道如何解决它。 It works fine on my kotlin project, that somebody else set up.
它在我的kotlin项目上工作得很好,其他人设置了。
It looks like you are missing AndroidInjectionModule (or AndroidSupportInjectionModule if you use support fragments) installed on you AppComponent
. 它看起来像你缺少AndroidInjectionModule (或AndroidSupportInjectionModule如果您使用支持片段)安装在你
AppComponent
。
It should be like: 应该是这样的:
@Component(modules = {AndroidInjectionModule.class, MainAppModule.class})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.