Versions:
Dagger 2.16
Android Studio 3.2 Beta 1
Support Library: androidx.appcompat:appcompat:1.0.0-alpha3
When I use dagger.android.support.DaggerApplication as the base class for my Application, I receive this error upon compilation.
:app:kaptGenerateStubsDebugKotlin
e: C:\Users\Mitchell\StudioProjects\AndroidXDatabindingBug\app\build\tmp\kapt3\stubs\debug\com\github\magneticflux\androidxdatabindingbug\di\AppComponent.java:10: error: [Dagger/MissingBinding] java.util.Map<java.lang.Class<? extends androidx.fragment.app.Fragment>,javax.inject.Provider<dagger.android.AndroidInjector.Factory<? extends androidx.fragment.app.Fragment>>> cannot be provided without an @Provides-annotated method.
public abstract void inject(@org.jetbrains.annotations.NotNull()
^
java.util.Map<java.lang.Class<? extends androidx.fragment.app.Fragment>,javax.inject.Provider<dagger.android.AndroidInjector.Factory<? extends androidx.fragment.app.Fragment>>> is injected at
dagger.android.DispatchingAndroidInjector.<init>(injectorFactories)
dagger.android.DispatchingAndroidInjector<androidx.fragment.app.Fragment> is injected at
dagger.android.support.DaggerApplication.supportFragmentInjector
com.github.magneticflux.androidxdatabindingbug.MyApplication is injected at
com.github.magneticflux.androidxdatabindingbug.di.AppComponent.inject(com.github.magneticflux.androidxdatabindingbug.MyApplication)
:app:kaptDebugKotlin FAILED
FAILURE: Build failed with an exception.
When I replace import dagger.android.support.DaggerApplication with import dagger.android.DaggerApplication, the error goes away but I am unable to use DaggerAppCompatActivity or DaggerFragment from the support libraries.
A minimal project to reproduce the issue is located here: magneticflux-/AndroidXDagger2Bug, simply try to use the support library features and it will fail to compile.
A workaround is given by this commit: https://github.com/magneticflux-/AndroidXDagger2Bug/commit/33a8f49c406d0cc82ad43b5745d209f6b4bf8e56
If you're using the support application, you need AndroidInjectionSupportModule
@ronshapiro If the support module is required, why does adding a useless support fragment to be injected prevent the issue? Surely it should fail to be injected as well?
The "useless" fragment actually satisfies a binding that Dagger application requests, specifically the map of injectors for fragments. If there are no fragments that need injection, an empty map is needed to supply that binding - that's what AndroidInjectionSupportModule does. If there is, however, a contribution to that multibound map of injectors, AndroidInjectionSupportModule's @Multibinds method acts as a noop
That makes sense, thanks for explaining it; I don't have much experience with the advanced features of Dagger 2.
Most helpful comment
If you're using the support application, you need
AndroidInjectionSupportModule