Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger: MissingBinding Error #1540

Closed
reactivedroid opened this issue Jun 28, 2019 · 2 comments
Closed

Dagger: MissingBinding Error #1540

reactivedroid opened this issue Jun 28, 2019 · 2 comments

Comments

@reactivedroid
Copy link

reactivedroid commented Jun 28, 2019

While trying to build with the MVVM arch with ViewModelFactory using dagger multibinding, the build fails:

error: [Dagger/MissingBinding] java.util.Map<java.lang.Class<? extends androidx.lifecycle.ViewModel>,? extends javax.inject.Provider<androidx.lifecycle.ViewModel>> cannot be provided without an @Provides-annotated method.
public abstract interface AppComponent {
      java.util.Map<java.lang.Class<? extends androidx.lifecycle.ViewModel>,? extends javax.inject.Provider<androidx.lifecycle.ViewModel>> is injected at

The ViewModelKey used :

@Target(
    AnnotationTarget.FUNCTION,
    AnnotationTarget.PROPERTY_GETTER,
    AnnotationTarget.PROPERTY_SETTER
)
@Retention(AnnotationRetention.RUNTIME)
@MapKey
annotation class ViewModelKey(val value: KClass<out ViewModel>)

Versions
Dagger:2.23.2
Kotlin:1.3.40

In fact, I tried following the solutions mentioned here #1478 by moving the ViewModelKey to java but it didn't work. Other fixes like downgrading versions also did not work. Also, pls note that I am using the latest versions of Kotlin and Dagger. Pls help if I am missing something
@ronshapiro

@reactivedroid
Copy link
Author

Update
Converting both ViewModelKey and ViewModelFactory to java solved the problem. That means, the problem either exists with Dagger Annotation processing or KAPT

@reactivedroid
Copy link
Author

Update 2: Looks like this was a typical problem of declaration-site variance from Kotlin to Java conversion. Adding @JvmSuppressWildcards solved the problem.
private val providers: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant