简体   繁体   English

Dagger2问题“如果没有@ Provide-annotated方法,则无法提供”。

[英]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.

相关问题 Dagger2-没有@Inject构造函数或@Provides注释方法无法提供 - Dagger2 - cannot be provided without an @Inject constructor or from an @Provides-annotated method 如何修复 dagger2 库中的“如果没有 @Provides-annotated 方法就无法提供”错误 - How to fix “cannot be provided without an @Provides-annotated method” error in dagger2 library 不能在没有 @Provides 注释的方法的情况下提供(Android Kotlin 中的 Dagger 2) - Cannot be provided without an @Provides-annotated method (Dagger 2 in Android Kotlin) 如果没有@ Provide-annotated方法,则无法提供Dagger 2 - Dagger 2 cannot be provided without an @Provides-annotated method Dagger 2:没有 @Provides 注释的方法就无法提供 - Dagger 2: Cannot be provided without an @Provides-annotated method Dagger 2-如果没有@Provides注释的方法,则无法提供 - Dagger 2 - Cannot be provided without an @Provides-annotated method dagger2错误“没有@Inject构造函数或来自@ Provide-annotated方法,不能提供android.app.Application” - dagger2 error “android.app.Application cannot be provided without an @Inject constructor or from an @Provides-annotated method” 如何解决“如果没有 @Provides-annotated 方法就无法提供”。 - Kotlin - how to fix "cannot be provided without an @Provides-annotated method." - Kotlin 匕首/缺少绑定。 如果没有@Provides 注释的方法,则无法提供输出器 - Dagger/MissingBinding. Outputter cannot be provided without an @Provides-annotated method 匕首-MissingBinding地图 <Class<? extends ViewModel> ,供应商 <ViewModel> &gt;如果没有@Provides注释的方法,则无法提供 - Dagger - MissingBinding Map<Class<? extends ViewModel>,Provider<ViewModel>> cannot be provided without an @Provides-annotated method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM