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

Verbose android Injection fails with missing binding #170

Open
matejdro opened this issue Sep 9, 2019 · 1 comment
Open

Verbose android Injection fails with missing binding #170

matejdro opened this issue Sep 9, 2019 · 1 comment

Comments

@matejdro
Copy link

matejdro commented Sep 9, 2019

When doing android injection the verbose way (without ContributesAndroidInjection), dagger-reflect fails with Missing binding for java.util.Map<java.lang.String, javax.inject.Provider<dagger.android.AndroidInjector$Factory<?>>>.

Sample code:

@Singleton
@Component(
    modules = [
        AndroidInjectionModule::class,
        AppModule::class
    ]
)
interface AppComponent {
    fun inject(app: MyApp)
}

@Module(
    subcomponents = [MainActivitySubcomponent::class]
)
interface AppModule {
    @Binds
    @IntoMap
    @ClassKey(MainActivity::class)
    fun bindMainActivityInjectorFactory(
        factory: MainActivitySubcomponent.Factory
    ): AndroidInjector.Factory<*>
}

@Subcomponent
interface MainActivitySubcomponent : AndroidInjector<MainActivity> {
    @Subcomponent.Factory
    interface Factory : AndroidInjector.Factory<MainActivity>
}


class MyApp : Application(), HasAndroidInjector {
    @Inject
    lateinit var androidInjector: DispatchingAndroidInjector<Any>

    override fun onCreate() {
        Dagger
            .create(AppComponent::class.java)
            .inject(this)

        super.onCreate()
    }

    override fun androidInjector(): AndroidInjector<Any> = androidInjector
}

class MainActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        AndroidInjection.inject(this)
        super.onCreate(savedInstanceState)
    }
}

Reproduced with:

    implementation 'com.google.dagger:dagger-android:2.24'

    // Reproduced on Sun Aug 11 03:26:53 UTC snapshot
    implementation 'com.jakewharton.dagger:dagger-reflect:0.2.0-SNAPSHOT'

Running this with normal annotation processing dagger works fine.

@matejdro
Copy link
Author

matejdro commented Sep 9, 2019

I think the issue is that dagger-inject ignores @Multibinds annotation in dagger.android.AndroidInjectionModule

Workaround for the issue is to manually inject empty map:

    @Provides
    @JvmStatic
    fun provideEmptyStringMap()
            : Map<@JvmSuppressWildcards String, @JvmSuppressWildcards Provider<AndroidInjector.Factory<*>>> =
        emptyMap()

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