Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using @Qualifier, [Dagger/MissingBinding] int[] cannot be provided without an @Provides-annotated method

I've written the code below to get me an IntArray and it works fine when I'm not annotating it with @Qualifer, but when I do, I get the error message below:

My module file (both annotation and modules are in same file)

@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD)
annotation class ItemColorArray

@Module
class ModuleGeneral {
    @Provides
    @ItemColorArray
    fun provideItemColorArray(context: Context): IntArray {
        return context.resources.getIntArray(R.array.timetableItems)
    }
}

Usage inside a dialogFragment:

@Inject
@ItemColorArray
lateinit var itemColorArray: IntArray

Error message:

{fileAddress}\di\AppComponent.java:8: error: [Dagger/MissingBinding] int[] cannot be provided without an @Provides-annotated method.
public abstract interface AppComponent {
                ^
      int[] is injected at
          {packageName}.ui.dialogs.addSubject.AddSubjectDialog.itemColorArray

Again, everything works fine when I'm not using any @Qualifier. Using the @Named("xxx") qualifier produces the same error. Thanks in advance.

like image 972
SIMMORSAL Avatar asked Feb 28 '26 09:02

SIMMORSAL


1 Answers

Qualifiers with Kotlin on fields were fixed / improved with Dagger version 2.25.

Make sure to use the latest version and it should work.


Alternatively you can use @field:MyQualifier so that previous versions can pick it up.

like image 102
David Medenjak Avatar answered Mar 03 '26 00:03

David Medenjak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!