得到错误[Dagger / MissingBinding]

时间:2019-05-16 23:35:39

标签: java android dagger-2

我一直在关注Google的GithubBrowserSample作为参考。

通过将其插入MainActivity中,我已经使最后的匕首触手可及,现在收到以下错误。除了包括我已经在里面的东西以外,似乎找不到很多其他东西。

error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] java.util.Map<java.lang.String,javax.inject.Provider<dagger.android.AndroidInjector.Factory<? extends androidx.fragment.app.Fragment>>> cannot be provided without an @Provides-annotated method.
java.util.Map<java.lang.String,javax.inject.Provider<dagger.android.AndroidInjector.Factory<? extends androidx.fragment.app.Fragment>>> is injected at
dagger.android.DispatchingAndroidInjector.<init>(…, injectorFactoriesWithStringKeys)
dagger.android.DispatchingAndroidInjector<androidx.fragment.app.Fragment> is injected at
com.crosscare.MainActivity.dispatchingAndroidInjector
com.crosscare.MainActivity is injected at
dagger.android.AndroidInjector.inject(T)
component path: com.crosscare.di.AppComponent ? com.crosscare.di.MainActivityModule_ContributeMainActivity.MainActivitySubcomponent

MainActivity:

public class MainActivity extends AppCompatActivity implements HasSupportFragmentInjector {

    @Inject
    DispatchingAndroidInjector<Fragment> dispatchingAndroidInjector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public DispatchingAndroidInjector<Fragment> supportFragmentInjector() {
        return dispatchingAndroidInjector;
    }
}

AppComponent:

@Singleton
@Component(modules = {
        AndroidInjectionModule.class,
        AppModule.class,
        MainActivityModule.class
})
public interface AppComponent {
    @Component.Builder
    interface Builder {
        @BindsInstance Builder application(Application application);
        AppComponent build();
    }
    void inject(CrosscareApp crosscareApp);
}

任何建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

在更仔细地进行谷歌搜索后发现了这个问题。

对于androidx来说,我需要使用AndroidSupportInjectionModule而不是AndroidInjectionModule